ApcUniversalClassLoader (Component\ClassLoader)
Symfony\Component\ClassLoader\ApcUniversalClassLoader
class ApcUniversalClassLoader extends UniversalClassLoader
ApcUniversalClassLoader implements a "universal" autoloader cached in APC 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:
require 'vendor/symfony/src/Symfony/Component/ClassLoader/UniversalClassLoader.php';
require 'vendor/symfony/src/Symfony/Component/ClassLoader/ApcUniversalClassLoader.php';
use Symfony\Component\ClassLoader\ApcUniversalClassLoader;
$loader = new ApcUniversalClassLoader('apc.prefix.');
// 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',
));
// 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
useIncludePath(bool $useIncludePath) Turns on searching the include for class files. | from UniversalClassLoader | |
bool | getUseIncludePath() Can be used to check if the autoloader uses the include path to check for classes. | from UniversalClassLoader |
array | getNamespaces() Gets the configured namespaces. | from UniversalClassLoader |
array | getPrefixes() Gets the configured class prefixes. | from UniversalClassLoader |
array | getNamespaceFallbacks() Gets the directory(ies) to use as a fallback for namespaces. | from UniversalClassLoader |
array | getPrefixFallbacks() Gets the directory(ies) to use as a fallback for class prefixes. | from UniversalClassLoader |
registerNamespaceFallbacks(array $dirs) Registers the directory to use as a fallback for namespaces. | from UniversalClassLoader | |
registerNamespaceFallback(string $dir) Registers a directory to use as a fallback for namespaces. | from UniversalClassLoader | |
registerPrefixFallbacks(array $dirs) Registers directories to use as a fallback for class prefixes. | from UniversalClassLoader | |
registerPrefixFallback(string $dir) Registers a directory to use as a fallback for class prefixes. | from UniversalClassLoader | |
registerNamespaces(array $namespaces) Registers an array of namespaces. | from UniversalClassLoader | |
registerNamespace(string $namespace, array|string $paths) Registers a namespace. | from UniversalClassLoader | |
registerPrefixes(array $classes) Registers an array of classes using the PEAR naming convention. | from UniversalClassLoader | |
registerPrefix(string $prefix, array|string $paths) Registers a set of classes using the PEAR naming convention. | from UniversalClassLoader | |
register(bool $prepend = false) Registers this instance as an autoloader. | from UniversalClassLoader | |
bool|null | loadClass(string $class) Loads the given class or interface. | from UniversalClassLoader |
string|null | findFile(string $class) Finds a file by class name while caching lookups to APC. | |
__construct(string $prefix) Constructor. |
Details
public useIncludePath(bool $useIncludePath)
Turns on searching the include for class files.
Allows easy loading of installed PEAR packages.
public bool getUseIncludePath()
Can be used to check if the autoloader uses the include path to check for classes.
public array getNamespaces()
Gets the configured namespaces.
public array getPrefixes()
Gets the configured class prefixes.
public array getNamespaceFallbacks()
Gets the directory(ies) to use as a fallback for namespaces.
public array getPrefixFallbacks()
Gets the directory(ies) to use as a fallback for class prefixes.
public registerNamespaceFallbacks(array $dirs)
Registers the directory to use as a fallback for namespaces.
public registerNamespaceFallback(string $dir)
Registers a directory to use as a fallback for namespaces.
public registerPrefixFallbacks(array $dirs)
Registers directories to use as a fallback for class prefixes.
public registerPrefixFallback(string $dir)
Registers a directory to use as a fallback for class prefixes.
public registerNamespaces(array $namespaces)
Registers an array of namespaces.
public registerNamespace(string $namespace, array|string $paths)
Registers a namespace.
public registerPrefixes(array $classes)
Registers an array of classes using the PEAR naming convention.
public registerPrefix(string $prefix, array|string $paths)
Registers a set of classes using the PEAR naming convention.
public register(bool $prepend = false)
Registers this instance as an autoloader.
public bool|null loadClass(string $class)
Loads the given class or interface.
public string|null findFile(string $class)
Finds a file by class name while caching lookups to APC.
public __construct(string $prefix)
Constructor.
© 2004–2016 Fabien Potencier
Licensed under the MIT License.
http://api.symfony.com/3.0/Symfony/Component/ClassLoader/ApcUniversalClassLoader.html