The Class Loader Adapter provides a common interface to interact with a number of different class loaders.
This package is auto-updated.
Last update: 2023-09-10 06:48:02 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'); $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.