class XcacheClassLoader

XcacheClassLoader implements a wrapping autoloader cached in Xcache for PHP 5.3.

It expects an object implementing a findFile method to find the file. This allows using it as a wrapper around the other loaders of the component (the ClassLoader and the UniversalClassLoader for instance) but also around any other autoloader following this convention (the Composer one for instance)

$loader = new ClassLoader();

// register classes with namespaces
$loader->add('Symfony\Component', __DIR__.'/component');
$loader->add('Symfony',           __DIR__.'/framework');

$cachedLoader = new XcacheClassLoader('my_prefix', $loader);

// activate the cached autoloader
$cachedLoader->register();

// eventually deactivate the non-cached loader if it was registered previously
// to be sure to use the cached one.
$loader->unregister();

Methods

__construct(string $prefix, object $classFinder)

Constructor.

register(Boolean $prepend = false)

Registers this instance as an autoloader.

unregister()

Unregisters this instance as an autoloader.

Boolean|null
loadClass(string $class)

Loads the given class or interface.

string|null
findFile(string $class)

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

Details

at line line 59
__construct(string $prefix, object $classFinder)

Constructor.

Parameters

string $prefix A prefix to create a namespace in Xcache
object $classFinder An object that implements findFile() method.

Exceptions

RuntimeException
InvalidArgumentException

at line line 78
register(Boolean $prepend = false)

Registers this instance as an autoloader.

Parameters

Boolean $prepend Whether to prepend the autoloader or not

at line line 86
unregister()

Unregisters this instance as an autoloader.

at line line 98
Boolean|null loadClass(string $class)

Loads the given class or interface.

Parameters

string $class The name of the class

Return Value

Boolean|null True, if loaded

at line line 114
string|null findFile(string $class)

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

Parameters

string $class A class name to resolve to file

Return Value

string|null