ClassLoader
in package
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.
Tags
Table of Contents
- $apcuPrefix : mixed
- $classMap : mixed
- $classMapAuthoritative : mixed
- $fallbackDirsPsr0 : mixed
- $fallbackDirsPsr4 : mixed
- $missingClasses : mixed
- $prefixDirsPsr4 : mixed
- $prefixesPsr0 : mixed
- $prefixLengthsPsr4 : mixed
- $useIncludePath : mixed
- add() : mixed
- Registers a set of PSR-0 directories for a given prefix, either appending or prepending to the ones previously set for this prefix.
- addClassMap() : mixed
- addPsr4() : mixed
- Registers a set of PSR-4 directories for a given namespace, either appending or prepending to the ones previously set for this namespace.
- findFile() : string|false
- Finds the path to the file where the class is defined.
- getApcuPrefix() : string|null
- The APCu prefix in use, or null if APCu caching is not enabled.
- getClassMap() : mixed
- getFallbackDirs() : mixed
- getFallbackDirsPsr4() : mixed
- getPrefixes() : mixed
- getPrefixesPsr4() : mixed
- getUseIncludePath() : bool
- Can be used to check if the autoloader uses the include path to check for classes.
- isClassMapAuthoritative() : bool
- Should class lookup fail if not found in the current class map?
- loadClass() : bool|null
- Loads the given class or interface.
- register() : mixed
- Registers this instance as an autoloader.
- set() : mixed
- Registers a set of PSR-0 directories for a given prefix, replacing any others previously set for this prefix.
- setApcuPrefix() : mixed
- APCu prefix to use to cache found/not-found classes, if the extension is enabled.
- setClassMapAuthoritative() : mixed
- Turns off searching the prefix and fallback directories for classes that have not been registered with the class map.
- setPsr4() : mixed
- Registers a set of PSR-4 directories for a given namespace, replacing any others previously set for this namespace.
- setUseIncludePath() : mixed
- Turns on searching the include path for class files.
- unregister() : mixed
- Unregisters this instance as an autoloader.
- findFileWithExtension() : mixed
Properties
$apcuPrefix
private
mixed
$apcuPrefix
$classMap
private
mixed
$classMap
= array()
$classMapAuthoritative
private
mixed
$classMapAuthoritative
= false
$fallbackDirsPsr0
private
mixed
$fallbackDirsPsr0
= array()
$fallbackDirsPsr4
private
mixed
$fallbackDirsPsr4
= array()
$missingClasses
private
mixed
$missingClasses
= array()
$prefixDirsPsr4
private
mixed
$prefixDirsPsr4
= array()
$prefixesPsr0
private
mixed
$prefixesPsr0
= array()
$prefixLengthsPsr4
private
mixed
$prefixLengthsPsr4
= array()
$useIncludePath
private
mixed
$useIncludePath
= false
Methods
add()
Registers a set of PSR-0 directories for a given prefix, either appending or prepending to the ones previously set for this prefix.
public
add(string $prefix, array<string|int, mixed>|string $paths[, bool $prepend = false ]) : mixed
Parameters
- $prefix : string
-
The prefix
- $paths : array<string|int, mixed>|string
-
The PSR-0 root directories
- $prepend : bool = false
-
Whether to prepend the directories
Return values
mixed —addClassMap()
public
addClassMap(array<string|int, mixed> $classMap) : mixed
Parameters
- $classMap : array<string|int, mixed>
-
Class to filename map
Return values
mixed —addPsr4()
Registers a set of PSR-4 directories for a given namespace, either appending or prepending to the ones previously set for this namespace.
public
addPsr4(string $prefix, array<string|int, mixed>|string $paths[, bool $prepend = false ]) : mixed
Parameters
- $prefix : string
-
The prefix/namespace, with trailing '\'
- $paths : array<string|int, mixed>|string
-
The PSR-4 base directories
- $prepend : bool = false
-
Whether to prepend the directories
Tags
Return values
mixed —findFile()
Finds the path to the file where the class is defined.
public
findFile(string $class) : string|false
Parameters
- $class : string
-
The name of the class
Return values
string|false —The path if found, false otherwise
getApcuPrefix()
The APCu prefix in use, or null if APCu caching is not enabled.
public
getApcuPrefix() : string|null
Return values
string|null —getClassMap()
public
getClassMap() : mixed
Return values
mixed —getFallbackDirs()
public
getFallbackDirs() : mixed
Return values
mixed —getFallbackDirsPsr4()
public
getFallbackDirsPsr4() : mixed
Return values
mixed —getPrefixes()
public
getPrefixes() : mixed
Return values
mixed —getPrefixesPsr4()
public
getPrefixesPsr4() : mixed
Return values
mixed —getUseIncludePath()
Can be used to check if the autoloader uses the include path to check for classes.
public
getUseIncludePath() : bool
Return values
bool —isClassMapAuthoritative()
Should class lookup fail if not found in the current class map?
public
isClassMapAuthoritative() : bool
Return values
bool —loadClass()
Loads the given class or interface.
public
loadClass(string $class) : bool|null
Parameters
- $class : string
-
The name of the class
Return values
bool|null —True if loaded, null otherwise
register()
Registers this instance as an autoloader.
public
register([bool $prepend = false ]) : mixed
Parameters
- $prepend : bool = false
-
Whether to prepend the autoloader or not
Return values
mixed —set()
Registers a set of PSR-0 directories for a given prefix, replacing any others previously set for this prefix.
public
set(string $prefix, array<string|int, mixed>|string $paths) : mixed
Parameters
- $prefix : string
-
The prefix
- $paths : array<string|int, mixed>|string
-
The PSR-0 base directories
Return values
mixed —setApcuPrefix()
APCu prefix to use to cache found/not-found classes, if the extension is enabled.
public
setApcuPrefix(string|null $apcuPrefix) : mixed
Parameters
- $apcuPrefix : string|null
Return values
mixed —setClassMapAuthoritative()
Turns off searching the prefix and fallback directories for classes that have not been registered with the class map.
public
setClassMapAuthoritative(bool $classMapAuthoritative) : mixed
Parameters
- $classMapAuthoritative : bool
Return values
mixed —setPsr4()
Registers a set of PSR-4 directories for a given namespace, replacing any others previously set for this namespace.
public
setPsr4(string $prefix, array<string|int, mixed>|string $paths) : mixed
Parameters
- $prefix : string
-
The prefix/namespace, with trailing '\'
- $paths : array<string|int, mixed>|string
-
The PSR-4 base directories
Tags
Return values
mixed —setUseIncludePath()
Turns on searching the include path for class files.
public
setUseIncludePath(bool $useIncludePath) : mixed
Parameters
- $useIncludePath : bool
Return values
mixed —unregister()
Unregisters this instance as an autoloader.
public
unregister() : mixed
Return values
mixed —findFileWithExtension()
private
findFileWithExtension(mixed $class, mixed $ext) : mixed
Parameters
- $class : mixed
- $ext : mixed