function AbstractQueuedCachedClassLoader::loadClass in X Autoload 7.5
Callback for class loading. This will include ("require") the file found.
Parameters
string $class: The class to load.
Overrides AbstractClassLoaderDecorator::loadClass
File
- src/
ClassLoader/ AbstractQueuedCachedClassLoader.php, line 75
Class
- AbstractQueuedCachedClassLoader
- Bass class for cached class loader decorators where cache entries cannot be written one by one, but have to be written all at once instead.
Namespace
Drupal\xautoload\ClassLoaderCode
function loadClass($class) {
// Look if the cache has anything for this class.
if (isset($this->classFiles[$class])) {
$file = $this->classFiles[$class];
// The is_file() check may cost around 0.0045 ms per class file, but this
// depends on your system of course.
if (is_file($file)) {
require $file;
return;
}
$this->toBeDeleted[$class] = $file;
unset($this->classFiles[$class]);
++$this->n;
}
// Resolve cache miss.
$api = new LoadClassGetFileInjectedApi($class);
if ($this->finder
->apiFindFile($api, $class)) {
// Queue the result for the cache.
$this->toBeAdded[$class] = $this->classFiles[$class] = $api
->getFile();
++$this->n;
}
// Save the cache if enough has been queued up.
if ($this->n >= $this->nMax) {
$this->classFiles = $this
->updateClassFiles($this->toBeAdded, $this->toBeDeleted);
$this->toBeDeleted = array();
$this->toBeAdded = array();
$this->nMax *= 2;
$this->n = 0;
}
}