UniversalClassLoader deprecated
class UniversalClassLoader
deprecated
UniversalClassLoader implements a "universal" autoloader for PHP 5.3.
It is able to load classes that use either:
The technical interoperability standards for PHP 5.3 namespaces and class names (https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md);
The PEAR naming convention for classes (http://pear.php.net/).
Classes from a sub-namespace or a sub-hierarchy of PEAR classes can be looked for in a list of locations to ease the vendoring of a sub-set of classes for large projects.
Example usage:
$loader = new UniversalClassLoader();
// register classes with namespaces
$loader->registerNamespaces(array(
'Symfony\Component' => __DIR__.'/component',
'Symfony' => __DIR__.'/framework',
'Sensio' => array(__DIR__.'/src', __DIR__.'/vendor'),
));
// register a library using the PEAR naming convention
$loader->registerPrefixes(array(
'Swift_' => __DIR__.'/Swift',
));
// to enable searching the include path (e.g. for PEAR packages)
$loader->useIncludePath(true);
// activate the autoloader
$loader->register();
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
Turns on searching the include for class files. Allows easy loading of installed PEAR packages.
Can be used to check if the autoloader uses the include path to check for classes.
Gets the configured namespaces.
Gets the configured class prefixes.
Gets the directory(ies) to use as a fallback for namespaces.
Gets the directory(ies) to use as a fallback for class prefixes.
Registers the directory to use as a fallback for namespaces.
Registers a directory to use as a fallback for namespaces.
Registers directories to use as a fallback for class prefixes.
Registers a directory to use as a fallback for class prefixes.
Registers an array of namespaces.
Registers a namespace.
Registers an array of classes using the PEAR naming convention.
Registers a set of classes using the PEAR naming convention.
Registers 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 78
useIncludePath(bool $useIncludePath)
Turns on searching the include for class files. Allows easy loading of installed PEAR packages.
at line line 89
bool
getUseIncludePath()
Can be used to check if the autoloader uses the include path to check for classes.
at line line 99
array
getNamespaces()
Gets the configured namespaces.
at line line 109
array
getPrefixes()
Gets the configured class prefixes.
at line line 119
array
getNamespaceFallbacks()
Gets the directory(ies) to use as a fallback for namespaces.
at line line 129
array
getPrefixFallbacks()
Gets the directory(ies) to use as a fallback for class prefixes.
at line line 139
registerNamespaceFallbacks(array $dirs)
Registers the directory to use as a fallback for namespaces.
at line line 149
registerNamespaceFallback(string $dir)
Registers a directory to use as a fallback for namespaces.
at line line 159
registerPrefixFallbacks(array $dirs)
Registers directories to use as a fallback for class prefixes.
at line line 169
registerPrefixFallback(string $dir)
Registers a directory to use as a fallback for class prefixes.
at line line 179
registerNamespaces(array $namespaces)
Registers an array of namespaces.
at line line 192
registerNamespace(string $namespace, array|string $paths)
Registers a namespace.
at line line 202
registerPrefixes(array $classes)
Registers an array of classes using the PEAR naming convention.
at line line 215
registerPrefix(string $prefix, array|string $paths)
Registers a set of classes using the PEAR naming convention.
at line line 225
register(bool $prepend = false)
Registers this instance as an autoloader.
at line line 237
bool|null
loadClass(string $class)
Loads the given class or interface.
at line line 253
string|null
findFile(string $class)
Finds the path to the file where the class is defined.