1. Open Power Autoloader

Currently, there is a couple of universal class loaders available. We have SplClassLoader which is the default implementation, the Universal Class Loader from Symfony 2, and Zend_Loader from Zend Framework. However, they are either parts of bigger projects, or do not offer a satisfactory performance with the bigger number of namespaces. Open Power Autoloader is a collection of universal class loaders compatible with PSR-0 designed for performance. The general idea behind them comes from the fact, that if we attempt to build an autoloader for all the possible environments and situations, it will be extremely slow. Instead, we can have a group of smaller, specialized autoloaders that should be choosed according to the needs of the concrete environment. There are several rationales for this approach:

  1. The autoloader is configured and installed once, in the very beginning of the script. The rest of the application does not even have to be aware of it.
  2. Different environments have different needs that cannot be easily combined in a single loader.
  3. Simple autoloader improves the performance.
  4. The autoloader itself must be loaded manually, so the programmer should not be forced to write lots of require statements.
  5. The autoloader API does not have to be complex. All we need is to define the supported namespaces and paths to the file locations.

Currently, the project provides three autoloaders:

  • Opl\Autoloader\GenericLoader - a standard autoloader that translates the class names into file paths dynamically. It is good for the development and testing environments, where the class hierarchy can be changed very often. It is also suitable for low-volume websites.
  • Opl\Autoloader\ClassMapLoader - an autoloader that uses the pregenerated class map loaded from an external file. It provides the biggest performance, but it requires to regenerate the map manually every time the class hierarchy is changed. It is suitable for production environments.
  • Opl\Autoloader\PHARLoader - a variant of ClassMapLoader for self-contained web and console applications packed in PHAR archives.

They are accompanied by a class map building library and a console command for Symfony 2 Command-Line Interface that does the same.

This text is licensed under Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 United States license.