Home arrow PHP arrow Using Directory Iterators to Build Loader Apps in PHP

Using Directory Iterators to Build Loader Apps in PHP

Welcome to the final part of an eight-part series on building loader applications in PHP. In this part, we'll improve on the loader class we developed in the previous part by using certain specific functions from the Standard PHP Library (SPL).

TABLE OF CONTENTS:
  1. Using Directory Iterators to Build Loader Apps in PHP
  2. Review: the previous class loader program
  3. Improving the definition of the Autoloader class using directory iterators
  4. Putting the Autoloader class into action
By: Alejandro Gervasio
Rating: starstarstarstarstar / 3
July 02, 2009

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

Among the bunch of useful features that were incorporated into PHP 5 a long time ago, aside from the improved object model, there's also a set of functions and classes that comprise what's commonly called the Standard PHP Library (SPL).

As you may have heard, this library permits you to perform several clever tasks through a powerful API, such as working with predefined interfaces, traversing arrays and directories easily, loading classes automatically, and so forth. But it's quite possible that at this point you may be wondering what the SPL has to do with building loader applications.

Well, I'm glad you asked, since some of the classes and functions that come packaged with the Standard PHP Library allow you to develop this kind of application in a much more compact and readable way, simplifying the code required for including specified resources and making it easier to create recursive methods.

In the preceding part of this series I explained how to create a loader program that could recursively search for a specified class through the file system on the web server.

While this sample application does its work pretty well when it comes to including classes in a transparent way, there's plenty of room to improve its recursive loading method. And here's where the SPL comes in, since it's possible to use a combination of its "spl_autoload_register()" function and its RecursiveDirectoryIterator class to refactor the method in question and make it shorter and tightrer.

So, with that goal in mind, in this final chapter of the series I'm going to improve the loader class developed in the previous one by incorporating some of the aforementioned SPL functions and classes.

Are you ready to discover the power of using directory iterators for building a more efficient class loading program in PHP 5? Then, don't waste more time in preliminaries; start reading right now!



 
 
>>> More PHP Articles          >>> More By Alejandro Gervasio
 

blog comments powered by Disqus
   

PHP ARTICLES

- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...
- PHP: Building Concrete Validators
- Sanitizing Input with PHP
- Executing Shell Commands with PHP
- Handling File Data with PHP
- File Security and Resources with PHP
- ArrayObject PHP Class Examples
- ArrayObject PHP Class: An Introduction
- Getting File System Data with PHP
- PHP Tools for Working with the File and Oper...
- Working with the File and Operating System w...
- PHP Proxy Patterns: Completing a Blog


© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 11 - Follow our Sitemap

Dev Shed Tutorial Topics: