HomePHP Working with Directory Iterators and Proxy Classes with PHP 5
Working with Directory Iterators and Proxy Classes with PHP 5
If you’re a strong advocate of using pattern-based programming for developing your PHP applications, then this pair of comprehensive tutorials might find a place on your quick reference list. Welcome to the concluding part of the series “Building Proxy Classes with PHP 5.” In two parts, this series introduces the foundations of how to apply the proxy pattern with PHP 5, and it accompanies the corresponding theory with extensive code samples.
Before I go deeper into the subject of this final article, let me refresh quickly the topics that I covered in the preceding article. As you'll possibly recall, over the course of the first part of the series, I explained the core concepts related to applying the proxy design pattern in PHP 5.
However, if this pattern is still a pretty unfamiliar thing to you, allow me to explain briefly what it does. Basically, in the proxy pattern, a class (in this case, it's called "proxy") accesses all the methods that belong to other classes. In other words, the proxy acts like an intermediate entity for a selected object, a fact that reminds one closely the behavior of different proxy servers.
So, having defined the basic logic that drives this pattern, the question is: why would we use it? Well, to be frank, the pattern can be used in those cases where you want to avoid an unnecessary instantiation of a given class, which will be used only when the application you're working with really demands it. At first glance, this may seem like an insignificant benefit if you're trying to boost the overall performance of your web applications, but there are times that working with many objects at the same time can bring about a notable overload on the server.
So far, so good. Assuming that the proxy pattern isn't an unknown topic to you anymore, let me tell you what this final article is about. Since in the first part of the series I showed you how to create a proxy class for processing simple XML strings, in this installment I'm going to teach you how to create a proxy object that can be used in conjunction with the "DirectoryIterator" class that comes with PHP 5.
Does this sound interesting and educational to you? Then it's time to learn how to couple proxy classes and iterators. Let's get started!