class ClassLoader

ClassLoader implements an PSR-0 class loader

See https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md

$loader = new ClassLoader();

// register classes with namespaces
$loader->addPrefix('Symfony\Component', __DIR__.'/component');
$loader->addPrefix('Symfony',           __DIR__.'/framework');

// activate the autoloader
$loader->register();

// to enable searching the include path (e.g. 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.

Methods

array
getPrefixes()

Returns prefixes.

array
getFallbackDirs()

Returns fallback directories.

addPrefixes(array $prefixes)

Adds prefixes.

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

Registers a set of classes

setUseIncludePath(Boolean $useIncludePath)

Turns on searching the include for class files.

Boolean
getUseIncludePath()

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

register(Boolean $prepend = false)

Registers this instance as an autoloader.

unregister()

Unregisters this instance as an autoloader.

Boolean|null
loadClass(string $class)

Loads the given class or interface.

string|null
findFile(string $class)

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

Details

at line line 51
array getPrefixes()

Returns prefixes.

Return Value

array

at line line 61
array getFallbackDirs()

Returns fallback directories.

Return Value

array

at line line 71
addPrefixes(array $prefixes)

Adds prefixes.

Parameters

array $prefixes Prefixes to add

at line line 84
addPrefix(string $prefix, array|string $paths)

Registers a set of classes

Parameters

string $prefix The classes prefix
array|string $paths The location(s) of the classes

at line line 108
setUseIncludePath(Boolean $useIncludePath)

Turns on searching the include for class files.

Parameters

Boolean $useIncludePath

at line line 119
Boolean getUseIncludePath()

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

Return Value

Boolean

at line line 129
register(Boolean $prepend = false)

Registers this instance as an autoloader.

Parameters

Boolean $prepend Whether to prepend the autoloader or not

at line line 137
unregister()

Unregisters this instance as an autoloader.

at line line 149
Boolean|null loadClass(string $class)

Loads the given class or interface.

Parameters

string $class The name of the class

Return Value

Boolean|null True, if loaded

at line line 165
string|null findFile(string $class)

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

Parameters

string $class The name of the class

Return Value

string|null The path, if found