The ClassMapAutoloaderOverviewThe ClassMapAutoloader is designed with performance in mind. The idea behind it is simple: when asked to load a class, see if it's in the map, and, if so, load the file associated with the class in the map. This avoids unnecessary filesystem operations, and can also ensure the autoloader "plays nice" with opcode caches and PHP's realpath cache. In order to use the ClassMapAutoloader, you first need class maps. Zend Framework also provides a tool for generating these class maps; you can find it in bin/classmap_generator.php of the distribution. Full documentation of this too is provided in The Class Map Generator utility: bin/classmap_generator.php. Quick StartThe first step is to generate a class map file. You may run this over any directory containing source code anywhere underneath it.
This will create a file named Some/Directory/autoload_classmap.php, which is a PHP file returning an associative array that represents the class map. Within your code, you will now instantiate the ClassMapAutoloader, and provide it the location of the map.
At this point, you may now use any classes referenced in your class map. Configuration OptionsThe ClassMapAutoloader defines the following options.
ClassMapAutoloader OptionsAvailable MethodsExamplesExample #1 Using configuration to seed ClassMapAutoloader Often, you will want to configure your ClassMapAutoloader. These values may come from a configuration file, a cache (such as ShMem or memcached), or a simple PHP array. The following is an example of a PHP array that could be used to configure the autoloader:
An eqivalent INI style configuration might look like this:
Once you have your configuration, you can pass it either to the constructor of the ClassMapAutoloader, to its setOptions() method, or to registerAutoloadMaps().
|