Skip to content

Latest commit

 

History

History
39 lines (27 loc) · 1.25 KB

map_class_loader.rst

File metadata and controls

39 lines (27 loc) · 1.25 KB

single: ClassLoader; MapClassLoader

MapClassLoader

The Symfony\\Component\\ClassLoader\\MapClassLoader allows you to autoload files via a static map from classes to files. This is useful if you use third-party libraries which don't follow the PSR-0 standards and so can't use the PSR-0 class loader </components/class_loader/class_loader>.

The MapClassLoader can be used along with the PSR-0 class loader </components/class_loader/class_loader> by configuring and calling the register() method on both.

Note

The default behavior is to append the MapClassLoader on the autoload stack. If you want to use it as the first autoloader, pass true when calling the register() method. Your class loader will then be prepended on the autoload stack.

Usage

Using it is as easy as passing your mapping to its constructor when creating an instance of the MapClassLoader class:

require_once '/path/to/src/Symfony/Component/ClassLoader/MapClassLoader.php';

$mapping = array(
    'Foo' => '/path/to/Foo',
    'Bar' => '/path/to/Bar',
);

$loader = new MapClassLoader($mapping);

$loader->register();