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
Methods
- __construct() : mixed
 - add() : void
 - Registers a set of PSR-0 directories for a given prefix, either appending or prepending to the ones previously set for this prefix.
 - addClassMap() : void
 - addPsr4() : void
 - 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() : array<string, string>
 - getFallbackDirs() : array<int, string>
 - getFallbackDirsPsr4() : array<int, string>
 - getPrefixes() : array<string, array<int, string>>
 - getPrefixesPsr4() : array<string, array<int, string>>
 - getRegisteredLoaders() : array<string, self>
 - Returns the currently registered loaders keyed by their corresponding vendor directories.
 - 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() : true|null
 - Loads the given class or interface.
 - register() : void
 - Registers this instance as an autoloader.
 - set() : void
 - Registers a set of PSR-0 directories for a given prefix, replacing any others previously set for this prefix.
 - setApcuPrefix() : void
 - APCu prefix to use to cache found/not-found classes, if the extension is enabled.
 - setClassMapAuthoritative() : void
 - Turns off searching the prefix and fallback directories for classes that have not been registered with the class map.
 - setPsr4() : void
 - Registers a set of PSR-4 directories for a given namespace, replacing any others previously set for this namespace.
 - setUseIncludePath() : void
 - Turns on searching the include path for class files.
 - unregister() : void
 - Unregisters this instance as an autoloader.
 
Methods
__construct()
    public
                    __construct([string|null $vendorDir = null ]) : mixed
    Parameters
- $vendorDir : string|null = null
 
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<int, string>|string $paths[, bool $prepend = false ]) : void
    Parameters
- $prefix : string
 - 
                    
The prefix
 - $paths : array<int, string>|string
 - 
                    
The PSR-0 root directories
 - $prepend : bool = false
 - 
                    
Whether to prepend the directories
 
addClassMap()
    public
                    addClassMap(array<string, string> $classMap) : void
    Parameters
- $classMap : array<string, string>
 - 
                    
Class to filename map
 
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<int, string>|string $paths[, bool $prepend = false ]) : void
    Parameters
- $prefix : string
 - 
                    
The prefix/namespace, with trailing '\'
 - $paths : array<int, string>|string
 - 
                    
The PSR-4 base directories
 - $prepend : bool = false
 - 
                    
Whether to prepend the directories
 
Tags
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|nullgetClassMap()
    public
                    getClassMap() : array<string, string>
    Return values
array<string, string> —Array of classname => path
getFallbackDirs()
    public
                    getFallbackDirs() : array<int, string>
    Return values
array<int, string>getFallbackDirsPsr4()
    public
                    getFallbackDirsPsr4() : array<int, string>
    Return values
array<int, string>getPrefixes()
    public
                    getPrefixes() : array<string, array<int, string>>
    Return values
array<string, array<int, string>>getPrefixesPsr4()
    public
                    getPrefixesPsr4() : array<string, array<int, string>>
    Return values
array<string, array<int, string>>getRegisteredLoaders()
Returns the currently registered loaders keyed by their corresponding vendor directories.
    public
            static        getRegisteredLoaders() : array<string, self>
    Return values
array<string, self>getUseIncludePath()
Can be used to check if the autoloader uses the include path to check for classes.
    public
                    getUseIncludePath() : bool
    Return values
boolisClassMapAuthoritative()
Should class lookup fail if not found in the current class map?
    public
                    isClassMapAuthoritative() : bool
    Return values
boolloadClass()
Loads the given class or interface.
    public
                    loadClass(string $class) : true|null
    Parameters
- $class : string
 - 
                    
The name of the class
 
Return values
true|null —True if loaded, null otherwise
register()
Registers this instance as an autoloader.
    public
                    register([bool $prepend = false ]) : void
    Parameters
- $prepend : bool = false
 - 
                    
Whether to prepend the autoloader or not
 
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<int, string>|string $paths) : void
    Parameters
- $prefix : string
 - 
                    
The prefix
 - $paths : array<int, string>|string
 - 
                    
The PSR-0 base directories
 
setApcuPrefix()
APCu prefix to use to cache found/not-found classes, if the extension is enabled.
    public
                    setApcuPrefix(string|null $apcuPrefix) : void
    Parameters
- $apcuPrefix : string|null
 
setClassMapAuthoritative()
Turns off searching the prefix and fallback directories for classes that have not been registered with the class map.
    public
                    setClassMapAuthoritative(bool $classMapAuthoritative) : void
    Parameters
- $classMapAuthoritative : bool
 
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<int, string>|string $paths) : void
    Parameters
- $prefix : string
 - 
                    
The prefix/namespace, with trailing '\'
 - $paths : array<int, string>|string
 - 
                    
The PSR-4 base directories
 
Tags
setUseIncludePath()
Turns on searching the include path for class files.
    public
                    setUseIncludePath(bool $useIncludePath) : void
    Parameters
- $useIncludePath : bool
 
unregister()
Unregisters this instance as an autoloader.
    public
                    unregister() : void