class ClassLoader
deprecated
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.
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(bool $useIncludePath) Turns on searching the include for class files. | ||
bool | getUseIncludePath() Can be used to check if the autoloader uses the include path to check for classes. | |
register(bool $prepend = false) Registers this instance as an autoloader. | ||
unregister() Unregisters this instance as an autoloader. | ||
bool|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. |
Returns prefixes.
array |
Returns fallback directories.
array |
Adds prefixes.
array | $prefixes | Prefixes to add |
Registers a set of classes.
string | $prefix | The classes prefix |
array|string | $paths | The location(s) of the classes |
Turns on searching the include for class files.
bool | $useIncludePath |
Can be used to check if the autoloader uses the include path to check for classes.
bool |
Registers this instance as an autoloader.
bool | $prepend | Whether to prepend the autoloader or not |
Unregisters this instance as an autoloader.
Loads the given class or interface.
string | $class | The name of the class |
bool|null | True, if loaded |
Finds the path to the file where the class is defined.
string | $class | The name of the class |
string|null | The path, if found |
© 2004–2017 Fabien Potencier
Licensed under the MIT License.
http://api.symfony.com/4.0/Symfony/Component/ClassLoader/ClassLoader.html