Skip to content

RobLoach/class-loader-adapter

Repository files navigation

Class Loader Adapter

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

Design

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.

Interoperability

Usage

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');
$loader->addClassMap($map);

// Register the class loader so that the classes can be loaded accordingly.
$loader->register();

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.

About

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages