\Composer\AutoloadClassLoader

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.

Summary

Methods
Properties
Constants
getPrefixes()
getPrefixesPsr4()
getFallbackDirs()
getFallbackDirsPsr4()
getClassMap()
addClassMap()
add()
addPsr4()
set()
setPsr4()
setUseIncludePath()
getUseIncludePath()
setClassMapAuthoritative()
isClassMapAuthoritative()
setApcuPrefix()
getApcuPrefix()
register()
unregister()
loadClass()
findFile()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
findFileWithExtension()
$prefixLengthsPsr4
$prefixDirsPsr4
$fallbackDirsPsr4
$prefixesPsr0
$fallbackDirsPsr0
$useIncludePath
$classMap
$classMapAuthoritative
$missingClasses
$apcuPrefix
N/A

Properties

$prefixLengthsPsr4

$prefixLengthsPsr4

$prefixDirsPsr4

$prefixDirsPsr4

$fallbackDirsPsr4

$fallbackDirsPsr4

$prefixesPsr0

$prefixesPsr0

$fallbackDirsPsr0

$fallbackDirsPsr0

$useIncludePath

$useIncludePath

$classMap

$classMap

$classMapAuthoritative

$classMapAuthoritative

$missingClasses

$missingClasses

$apcuPrefix

$apcuPrefix

Methods

getPrefixes()

getPrefixes() : mixed

Returns

mixed —

getPrefixesPsr4()

getPrefixesPsr4() : mixed

Returns

mixed —

getFallbackDirs()

getFallbackDirs() : mixed

Returns

mixed —

getFallbackDirsPsr4()

getFallbackDirsPsr4() : mixed

Returns

mixed —

getClassMap()

getClassMap() : mixed

Returns

mixed —

addClassMap()

addClassMap(array  $classMap) : mixed

Parameters

array $classMap

Class to filename map

Returns

mixed —

add()

add(string  $prefix, array|string  $paths, bool  $prepend = false) : mixed

Registers a set of PSR-0 directories for a given prefix, either appending or prepending to the ones previously set for this prefix.

Parameters

string $prefix

The prefix

array|string $paths

The PSR-0 root directories

bool $prepend

Whether to prepend the directories

Returns

mixed —

addPsr4()

addPsr4(string  $prefix, array|string  $paths, bool  $prepend = false) : mixed

Registers a set of PSR-4 directories for a given namespace, either appending or prepending to the ones previously set for this namespace.

Parameters

string $prefix

The prefix/namespace, with trailing '\'

array|string $paths

The PSR-4 base directories

bool $prepend

Whether to prepend the directories

Throws

\InvalidArgumentException

Returns

mixed —

set()

set(string  $prefix, array|string  $paths) : mixed

Registers a set of PSR-0 directories for a given prefix, replacing any others previously set for this prefix.

Parameters

string $prefix

The prefix

array|string $paths

The PSR-0 base directories

Returns

mixed —

setPsr4()

setPsr4(string  $prefix, array|string  $paths) : mixed

Registers a set of PSR-4 directories for a given namespace, replacing any others previously set for this namespace.

Parameters

string $prefix

The prefix/namespace, with trailing '\'

array|string $paths

The PSR-4 base directories

Throws

\InvalidArgumentException

Returns

mixed —

setUseIncludePath()

setUseIncludePath(bool  $useIncludePath) : mixed

Turns on searching the include path for class files.

Parameters

bool $useIncludePath

Returns

mixed —

getUseIncludePath()

getUseIncludePath() : bool

Can be used to check if the autoloader uses the include path to check for classes.

Returns

bool —

setClassMapAuthoritative()

setClassMapAuthoritative(bool  $classMapAuthoritative) : mixed

Turns off searching the prefix and fallback directories for classes that have not been registered with the class map.

Parameters

bool $classMapAuthoritative

Returns

mixed —

isClassMapAuthoritative()

isClassMapAuthoritative() : bool

Should class lookup fail if not found in the current class map?

Returns

bool —

setApcuPrefix()

setApcuPrefix(string|null  $apcuPrefix) : mixed

APCu prefix to use to cache found/not-found classes, if the extension is enabled.

Parameters

string|null $apcuPrefix

Returns

mixed —

getApcuPrefix()

getApcuPrefix() : string|null

The APCu prefix in use, or null if APCu caching is not enabled.

Returns

string|null —

register()

register(bool  $prepend = false) : mixed

Registers this instance as an autoloader.

Parameters

bool $prepend

Whether to prepend the autoloader or not

Returns

mixed —

unregister()

unregister() : mixed

Unregisters this instance as an autoloader.

Returns

mixed —

loadClass()

loadClass(string  $class) : bool|null

Loads the given class or interface.

Parameters

string $class

The name of the class

Returns

bool|null —

True if loaded, null otherwise

findFile()

findFile(string  $class) : string|false

Finds the path to the file where the class is defined.

Parameters

string $class

The name of the class

Returns

string|false —

The path if found, false otherwise

findFileWithExtension()

findFileWithExtension(mixed  $class, mixed  $ext) : mixed

Parameters

mixed $class
mixed $ext

Returns

mixed —