Psr4AutoloaderClass
A general-purpose implementation that includes the optional functionality of allowing multiple base directories for a single namespace prefix.
1 // instantiate the loader
2 $loader = new \Example\Psr4AutoloaderClass;
3
4 // register the autoloader
5 $loader->register();
6
7 // register the base directories for the namespace prefix
8 $loader->addNamespace('Foo\Bar', '/path/to/packages/foo-bar/src');
9 $loader->addNamespace('Foo\Bar', '/path/to/packages/foo-bar/tests');The following line would cause the autoloader to attempt to load the
\Foo\Bar\Qux\Quux class from /path/to/packages/foo-bar/src/Qux/Quux.php:
1 new \Foo\Bar\Qux\Quux;The following line would cause the autoloader to attempt to load the
\Foo\Bar\Qux\QuuxTest class from /path/to/packages/foo-bar/tests/Qux/QuuxTest.php:
1 new \Foo\Bar\Qux\QuuxTest;Code obtained from PHP Framework Interoperability Group