ClassLoader

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

Methods

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

add(string $prefix,array|string $paths,boolean $prepend = false)

Arguments

$prefix

string

The prefix

$paths

array|string

The PSR-0 root directories

$prepend

boolean

Whether to prepend the directories

addClassMap

addClassMap(array $classMap)

Arguments

$classMap

array

Class to filename map

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

addPsr4(string $prefix,array|string $paths,boolean $prepend = false)
Throws
\InvalidArgumentException

Arguments

$prefix

string

The prefix/namespace, with trailing '\'

$paths

array|string

The PSR-4 base directories

$prepend

boolean

Whether to prepend the directories

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

findFile(string $class): string|false

Arguments

$class

string

The name of the class

Response

string|false

The path if found, false otherwise

findFileWithExtension

findFileWithExtension( $class, $ext)

Arguments

$class

$ext

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

getApcuPrefix(): string|null

Response

string|null

getClassMap

getClassMap()

getFallbackDirs

getFallbackDirs()

getFallbackDirsPsr4

getFallbackDirsPsr4()

getPrefixes

getPrefixes()

getPrefixesPsr4

getPrefixesPsr4()

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

getUseIncludePath(): boolean

Response

boolean

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

isClassMapAuthoritative(): boolean

Response

boolean

Loads the given class or interface.

loadClass(string $class): boolean|null

Arguments

$class

string

The name of the class

Response

boolean|null

True if loaded, null otherwise

Registers this instance as an autoloader.

register(boolean $prepend = false)

Arguments

$prepend

boolean

Whether to prepend the autoloader or not

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

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

Arguments

$prefix

string

The prefix

$paths

array|string

The PSR-0 base directories

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

setApcuPrefix(string|null $apcuPrefix)

Arguments

$apcuPrefix

string|null

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

setClassMapAuthoritative(boolean $classMapAuthoritative)

Arguments

$classMapAuthoritative

boolean

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

setPsr4(string $prefix,array|string $paths)
Throws
\InvalidArgumentException

Arguments

$prefix

string

The prefix/namespace, with trailing '\'

$paths

array|string

The PSR-4 base directories

Turns on searching the include path for class files.

setUseIncludePath(boolean $useIncludePath)

Arguments

$useIncludePath

boolean

Unregisters this instance as an autoloader.

unregister()

Properties

prefixLengthsPsr4

prefixLengthsPsr4 :

Type(s)

prefixDirsPsr4

prefixDirsPsr4 :

Type(s)

fallbackDirsPsr4

fallbackDirsPsr4 :

Type(s)

prefixesPsr0

prefixesPsr0 :

Type(s)

fallbackDirsPsr0

fallbackDirsPsr0 :

Type(s)

useIncludePath

useIncludePath :

Type(s)

classMap

classMap :

Type(s)

classMapAuthoritative

classMapAuthoritative :

Type(s)

missingClasses

missingClasses :

Type(s)

apcuPrefix

apcuPrefix :

Type(s)