|
|||||||||||||||
Current Texts Comic Imprint Calendar Search PHP-Classes Container-Wizard main.s21 |
|||||||||||||||
Categories
{{login}}
|
paran: Autoloader
The first in the series is the Autoloader, which is usually the second line of code within one of my projects - with the first requiring the Autoloader.
<?php
Note that Loader does not register an autoload handler by himself - it leaves that to you, which gives you more control over the process. Also note that the indexes are merged together - if a class occurs within classes and project, the class within project will be loaded. Concerning the directory structure, the Loader supports complex structures with subdirectories, allowing you to build a structure best representing your work. It assumes that a file <name>.php contains the class <name>, but allows for certain special names as well: AbstractClass.abstract.php While the first three allow you organize your classes more clearly, the fourth file will be included instantly. This should be used for standalone functions, which cannot be autoloaded on demand. But since you're a good OO programmer, you won't need those, rrright? Also note that "class" is optional. Now recursively indexing whole directory trees might become cumbersome at some point and there is little reason why the same process should be started over and over again. To improve performance, you can store the results of a run within a simple index file (which is basically a CVS file containing classes and directories):
<?php
Now an index is written to index.txt first time or whenever a class is requested which cannot be found. Performance can be increased further by vetoing certain directories:
<?php
Now all directories matching ".svn" (exact match) will be ignored during any index run. Dieser Text ist Teil der Serie Paran in Action paran: Autoloader CommentsPlease note: comments posted won't be visible immediately, as they will be checked for harmful content. |