Class

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:

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

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
registerPrefixFallbacks(array $dirs)

Registers the 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(Boolean $prepend = false)

Registers this instance as an autoloader.

from UniversalClassLoader
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

in UniversalClassLoader at line 69
public array getNamespaces()

Gets the configured namespaces.

Return Value

array A hash with namespaces as keys and directories as values

in UniversalClassLoader at line 79
public array getPrefixes()

Gets the configured class prefixes.

Return Value

array A hash with class prefixes as keys and directories as values

in UniversalClassLoader at line 89
public array getNamespaceFallbacks()

Gets the directory(ies) to use as a fallback for namespaces.

Return Value

array An array of directories

in UniversalClassLoader at line 99
public array getPrefixFallbacks()

Gets the directory(ies) to use as a fallback for class prefixes.

Return Value

array An array of directories

in UniversalClassLoader at line 111
public registerNamespaceFallbacks(array $dirs)

Registers the directory to use as a fallback for namespaces.

Parameters

array $dirs An array of directories

in UniversalClassLoader at line 123
public registerPrefixFallbacks(array $dirs)

Registers the directory to use as a fallback for class prefixes.

Parameters

array $dirs An array of directories

in UniversalClassLoader at line 135
public registerNamespaces(array $namespaces)

Registers an array of namespaces

Parameters

array $namespaces An array of namespaces (namespaces as keys and locations as values)

in UniversalClassLoader at line 150
public registerNamespace(string $namespace, array|string $paths)

Registers a namespace.

Parameters

string $namespace The namespace
array|string $paths The location(s) of the namespace

in UniversalClassLoader at line 162
public registerPrefixes(array $classes)

Registers an array of classes using the PEAR naming convention.

Parameters

array $classes An array of classes (prefixes as keys and locations as values)

in UniversalClassLoader at line 177
public registerPrefix(string $prefix, array|string $paths)

Registers a set of classes using the PEAR naming convention.

Parameters

string $prefix The classes prefix
array|string $paths The location(s) of the classes

in UniversalClassLoader at line 189
public register(Boolean $prepend = false)

Registers this instance as an autoloader.

Parameters

Boolean $prepend Whether to prepend the autoloader or not

in UniversalClassLoader at line 199
public loadClass(string $class)

Loads the given class or interface.

Parameters

string $class The name of the class

at line 90
public string|null findFile(string $class)

Finds a file by class name while caching lookups to APC.

Parameters

string $class A class name to resolve to file

Return Value

string|null The path, if found

at line 74
public __construct(string $prefix)

Constructor.

Parameters

string $prefix A prefix to create a namespace in APC