The Class Loader Adapter provides a common interface to interact with a number of different class loaders.

dev-master 2013-07-18 16:05 UTC

This package is auto-updated.

Last update: 2024-07-10 08:26:15 UTC


Common interface to interact with a number of different class loaders.


It is recommended to just have one class loader interface for your application, and initialize and use it only once during your application's starting point. It can, however, sometimes be handy to allow swapping the class loader while still using the same API to interact with it. Class Loader Adapter aims to provide that interface commonality between a bunch of different third-party class loaders.



Initialize with whichever class loader you want to use:

// Initialize the loader with the Symfony UniversalClassLoader.
$loader = new RobLoach\ClassLoaderAdapter\Symfony\UniversalClassLoader();

// Initialize the loader with the Composer ClassLoader.
$loader = new RobLoach\ClassLoaderAdapter\Composer\ClassLoader();

Since all of the Class Loader Adapter loaders use the same ClassLoaderInterface , you can interact with them all the same way.

// Add a namespace prefix.
$loader->addPrefix('Foo', 'src/');

// Add a class map.
$map = array('Foo\Bar' => 'src/Foo/Bar.php');

// Register the class loader so that the classes can be loaded accordingly.

Although the interface is in place, class loader functionality and support slightly differs from class loader to class loader. Take note of this when switching between the class loaders.