This brief documents presents the essential concepts behind Automap and the main benefits it can bring to your applications.
Automap is a map-based PHP autoloader. As such, it is composed of two parts :
A builder program scans the PHP scripts composing your application, detects the symbols they define (classes, interfaces...), and registers them into a map file. Once it is done, the map file contains a list of every symbols defined in your scripts, and each symbol is associated with the file it is defined in. The map file is built only once (or when PHP scripts are modified and define a new class). It is built using the PHP interpreter in command line mode (text/shell/command mode).
The map file is an integral part of the software and is distributed with the program scripts and the automap runtime.
At run time, the application's main script first includes the Automap runtime (a file named automap.phk) and, then, loads one or several map files. From this point on, any reference to a symbol present in one of the loaded maps triggers the autoloader and automatically loads the appropriate PHP script.
Note: We talk about symbols, and not classes because, even if PHP autoloading mechanism supports classes only, it can be extended in the future to autoload functions and constants too.
Main benefits : Compared to path-based autoloaders, Automap :
- is much faster as it avoids a lot of interaction with the file system,
- removes the constraints on file and directory naming,
- removes the limitation of one symbol per file,
- provides an optional PECL accelerator.