The StandardAutoloaderOverviewZend_Loader_StandardAutoloader is designed as a » PSR-0-compliant autoloader. It assumes a 1:1 mapping of the namespace+classname to the filesystem, wherein namespace separators and underscores are translated to directory separators. A simple statement that illustrates how resolution works is as follows:
Previous incarnations of PSR-0-compliant autoloaders in Zend Framework have relied upon the include_path for file lookups. This has led to a number of issues:
To solve these problems, the StandardAutoloader by default requires that you explicitly register namespace/path pairs (or vendor prefix/path pairs), and will only load a file if it exists within the given path. Multiple pairs may be provided. As a measure of last resort, you may also use the StandardAutoloader as a "fallback" autoloader -- one that will look for classes of any namespace or vendor prefix on the include_path. This practice is not recommended, however, due to performance implications. Finally, as with all autoloaders in Zend Framework, the StandardAutoloader is capable of registering itself with PHP's SPL autoloader registry.
Quick StartBasic use of the StandardAutoloader requires simply registering namespace/path pairs. This can either be done at instantiation, or via explicit method calls after the object has been initialized. Calling register() will register the autoloader with the SPL autoloader registry. By default, the class will register the "Zend" namespace to the directory above where its own classfile is located on the filesystem. Example #1 Manual Configuration
Example #2 Configuration at Instantiation The StandardAutoloader may also be configured at instantiation. Please note:
The following is equivalent to the previous example.
Configuration OptionsThe StandardAutoloader defines the following options.
StandardAutoloader OptionsAvailable MethodsExamplesPlease review the examples in the quick start for usage.
|