Symfony\Component\ClassLoader\UniversalClassLoader
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.
- Author: Fabien Potencier <fabien@symfony.com>
Synopsis
- // members
- private array $namespaces;
- private array $prefixes;
- private array $namespaceFallbacks;
- private array $prefixFallbacks;
- private $useIncludePath;
- // methods
- public void useIncludePath()
- public Boolean getUseIncludePath()
- public array getNamespaces()
- public array getPrefixes()
- public array getNamespaceFallbacks()
- public array getPrefixFallbacks()
- public void registerNamespaceFallbacks()
- public void registerNamespaceFallback()
- public void registerPrefixFallbacks()
- public void registerPrefixFallback()
- public void registerNamespaces()
- public void registerNamespace()
- public void registerPrefixes()
- public void registerPrefix()
- public void register()
- public Boolean|null loadClass()
- public string|null findFile()
Hierarchy
Extended by
Members
private
- $namespaceFallbacks
- $namespaces
- $prefixFallbacks
- $prefixes
- $useIncludePath
Methods
public
- findFile() — Finds the path to the file where the class is defined.
- getNamespaceFallbacks() — Gets the directory(ies) to use as a fallback for namespaces.
- getNamespaces() — Gets the configured namespaces.
- getPrefixFallbacks() — Gets the directory(ies) to use as a fallback for class prefixes.
- getPrefixes() — Gets the configured class prefixes.
- getUseIncludePath() — Can be used to check if the autoloader uses the include path to check for classes.
- loadClass() — Loads the given class or interface.
- register() — Registers this instance as an autoloader.
- registerNamespace() — Registers a namespace.
- registerNamespaceFallback() — Registers a directory to use as a fallback for namespaces.
- registerNamespaceFallbacks() — Registers the directory to use as a fallback for namespaces.
- registerNamespaces() — Registers an array of namespaces
- registerPrefix() — Registers a set of classes using the PEAR naming convention.
- registerPrefixFallback() — Registers a directory to use as a fallback for class prefixes.
- registerPrefixFallbacks() — Registers directories to use as a fallback for class prefixes.
- registerPrefixes() — Registers an array of classes using the PEAR naming convention.
- useIncludePath() — Turns on searching the include for class files. Allows easy loading of installed PEAR packages