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.
author | Fabien Potencier fabien@symfony.com |
---|---|
author | Jordi Boggiano j.boggiano@seld.be |
see | |
see | |
package | Default |
add(string $prefix,array|string $paths,boolean $prepend = false)
string
The prefix
array|string
The PSR-0 root directories
boolean
Whether to prepend the directories
addClassMap(array $classMap)
array
Class to filename map
addPsr4(string $prefix,array|string $paths,boolean $prepend = false)
Throws |
|
---|
string
The prefix/namespace, with trailing '\'
array|string
The PSR-4 base directories
boolean
Whether to prepend the directories
findFile(string $class): string|false
string
The name of the class
string|false
The path if found, false otherwise
findFileWithExtension( $class, $ext)
getApcuPrefix(): string|null
string|null
getClassMap()
getFallbackDirs()
getFallbackDirsPsr4()
getPrefixes()
getPrefixesPsr4()
getUseIncludePath(): boolean
boolean
isClassMapAuthoritative(): boolean
boolean
loadClass(string $class): boolean|null
string
The name of the class
boolean|null
True if loaded, null otherwise
register(boolean $prepend = false)
boolean
Whether to prepend the autoloader or not
set(string $prefix,array|string $paths)
string
The prefix
array|string
The PSR-0 base directories
setApcuPrefix(string|null $apcuPrefix)
string|null
setClassMapAuthoritative(boolean $classMapAuthoritative)
boolean
setPsr4(string $prefix,array|string $paths)
Throws |
|
---|
string
The prefix/namespace, with trailing '\'
array|string
The PSR-4 base directories
setUseIncludePath(boolean $useIncludePath)
boolean
unregister()
prefixLengthsPsr4 :
prefixDirsPsr4 :
fallbackDirsPsr4 :
prefixesPsr0 :
fallbackDirsPsr0 :
useIncludePath :
classMap :
classMapAuthoritative :
missingClasses :
apcuPrefix :