ClassLoader
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
Returns prefixes.
Returns fallback directories.
Adds prefixes.
Registers a set of classes.
Turns on searching the include for class files.
Can be used to check if the autoloader uses the include path to check for classes.
Registers this instance as an autoloader.
Unregisters this instance as an autoloader.
Loads the given class or interface.
Finds the path to the file where the class is defined.
Details
at line line 51
array
getPrefixes()
Returns prefixes.
at line line 61
array
getFallbackDirs()
Returns fallback directories.
at line line 71
addPrefixes(array $prefixes)
Adds prefixes.
at line line 84
addPrefix(string $prefix, array|string $paths)
Registers a set of classes.
at line line 112
setUseIncludePath(bool $useIncludePath)
Turns on searching the include for class files.
at line line 123
bool
getUseIncludePath()
Can be used to check if the autoloader uses the include path to check for classes.
at line line 133
register(bool $prepend = false)
Registers this instance as an autoloader.
at line line 141
unregister()
Unregisters this instance as an autoloader.
at line line 153
bool|null
loadClass(string $class)
Loads the given class or interface.
at line line 169
string|null
findFile(string $class)
Finds the path to the file where the class is defined.