ZF2 Autoloaders in ZF1 and/or PHP 5.2 Projects

This example/subproject is a backport of the ZF2 autoloaders to PHP 5.2. Instead
of namespaces, class prefixes are used, and all PHP 5.3-specific implementation
details (closures in tests, namespaces, __DIR__ magic constant, etc.) were
refactored to use standard PHP functionality available before PHP 5.3.

Additionally, the classes are under a ZendX_ prefix to prevent collisions (if
any) with ZF code and to allow installing side-by-side with a standard ZF
distribution.

FEATURES

PSR-0-compliant include_path autoloading

PSR-0-compliant per-prefix or namespace autoloading

Classmap autoloading, including classmap generation

Autoloader factory for loading several autoloader strategies at once

USAGE

SplAutoloader Interface

Each autoloader shipped implements the same interface,
ZendX_Loader_SplAutoloader. This interface is as follows:

The important pieces to remember is that autoloaders should typically be
configurable (and accept configuration via the constructor), the autoload
functionality should be defined via the autoload() method, and each should
register with spl_autoload_register() when register() is called.

Any autoloader that implements the above interface will work with the
AutoloaderFactory.

StandardAutoloader

The StandardAutoloader is a PSR-0-compliant autoloader. It features three use
cases:

include_path-based autoloading

Autoloading from specific namespace/directory pairs

Autoloading from specific vendor prefix/directory pairs

The above may be combined so that the same autoloader instance can be used to
autoload from a variety of PHP namespaces or vendor prefixes.

When resolving classes, namespaces or prefixes are searched in the order in
which they are registered. As such, you should register from most specific to
least specific if registering multiple namespaces/prefixes with a common root.
Otherwise, register from most used to least used to ensure the least number of
lookups.

ClassMapAutoloader

The ClassMapAutoloader utilizes class maps to do its work; a class map is simply
an associative array with class names for keys and filesystem locations for
values. You may pass it explicit arrays (or Traversable objects), or the
filesystem location of a PHP file that returns an array.

Class maps are perhaps the fastest possible way to autoload classes, and provide
the least possible liklihood of errors in resolution. They also work very well
with PHP's opcode and realpath caches.

The "-w" switch tells the tool to overwrite the classmap file if one already
exists. We recommend that you tell your IDE to execute this command when new
files are created under a given tree, create a continuous integration task to
build it, or create a deployment task to execute it.

AutoloaderFactory

The AutoloaderFactory can be used to configure autoloader instances and register
them with spl_autoload_register(); additionally, it can be used to initialize
many autoloading strategies at once. In particular, this is useful for providing
rapid application development advantages during early-stage development using
the StandardAutoloader, and run-time advantages during deployment using the
ClassMapAutoloader.

In all cases, autoloaders must implement ZendX_Loader_SplAutoloader.

Usage

Usage is straight-forward: pass an array of autoloader classname keys with an
array of configuration. Autoloaders are registered in the order passed, so
register the method you want to use to match first. In most cases, the first
autoloader should be a ClassMapAutoloader, and the last a StandardAutoloader
configured to act as a fallback autoloader.

The factory will attempt to autoload the specified autoloaders from the
include_path; if any autoloaders specified are not on the include_path,
you should call require_once with their path prior to execution.

When the factory method executes, it will load and initialize each autoloader
with the specified options, and then execute the register() method, ensuring
that autoloading is now in play.