$prefixLengthsPsr4
$prefixLengthsPsr4 :
ClassLoader implements a PSR-0, PSR-4 and classmap class loader.
$loader = new \Composer\Autoload\ClassLoader();
// register classes with namespaces
$loader->add('Symfony\Component', __DIR__.'/component');
$loader->add('Symfony', __DIR__.'/framework');
// activate the autoloader
$loader->register();
// to enable searching the include path (eg. for PEAR packages)
$loader->setUseIncludePath(true);
In this example, if you try to use a class in the Symfony\Component namespace or one of its children (Symfony\Component\Console for instance), the autoloader will first look for the class under the component/ directory, and it will then fallback to the framework/ directory if not found before giving up.
This class is loosely based on the Symfony UniversalClassLoader.
add(string $prefix, array|string $paths, boolean $prepend = false)
Registers a set of PSR-0 directories for a given prefix, either appending or prepending to the ones previously set for this prefix.
string | $prefix | The prefix |
array|string | $paths | The PSR-0 root directories |
boolean | $prepend | Whether to prepend the directories |
addPsr4(string $prefix, array|string $paths, boolean $prepend = false)
Registers a set of PSR-4 directories for a given namespace, either appending or prepending to the ones previously set for this namespace.
string | $prefix | The prefix/namespace, with trailing '\' |
array|string | $paths | The PSR-4 base directories |
boolean | $prepend | Whether to prepend the directories |
setPsr4(string $prefix, array|string $paths)
Registers a set of PSR-4 directories for a given namespace, replacing any others previously set for this namespace.
string | $prefix | The prefix/namespace, with trailing '\' |
array|string | $paths | The PSR-4 base directories |