PHP AutoLoad Code
Extensible PSR-0 compatible class autoloader for PHP 5.3+
Status: Beta
Brought to you by:
james_watts
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | PHP AutoLoad v1.0 Copyright (c) 2012 James Watts (SOLFENIX) http://www.solfenix.com This is FREE software, licensed under the GNU/GPL http://www.gnu.org/licenses/gpl.html The AutoLoad class provides a PSR-0 (https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md) compatible method to load required classes using namespaces for PHP 5.3+. For a class to the comply with the standard the following criteria must be met: - A fully-qualified namespace and class must have the following structure \<Vendor Name>\(<Namespace>\)*<Class Name> - Each namespace must have a top-level namespace ("Vendor Name"). - Each namespace can have as many sub-namespaces as it wishes. - Each namespace separator is converted to a DIRECTORY_SEPARATOR when loading from the file system. - Each "_" character in the CLASS NAME is converted to a DIRECTORY_SEPARATOR. The "_" character has no special meaning in the namespace. - The fully-qualified namespace and class is suffixed with ".php" when loading from the file system. - Alphabetic characters in vendor names, namespaces, and class names may be of any combination of lower case and upper case. To use the autoloader first include the class: require 'Solfenix/AutoLoad/AutoLoad.php'; Once the class is available the autoloader needs to be registered, for example: spl_autoload_register( 'Solfenix\AutoLoad\AutoLoad::run' ); The base path where your classes are located can be set if needed, for example: AutoLoad::setPath( array( 'path', 'to', 'files' ) ); This would resolve to path/to/files/<Vendor Name>/(<Namespace>/)*<Class Name>, however, the namespace would remain the same: use <Vendor Name>\(<Namespace>\)*<Class Name>; The extension used for your classes can also be set, for example: AutoLoad::setExtension( 'class.php' ); This would search for files ending in **.class.php**, for example: path/to/files/Solfenix/AutoLoad/AutoLoad.class.php |