function ClassFinder::loadClass in X Autoload 7.4
Same name and namespace in other branches
- 7.5 src/ClassFinder/ClassFinder.php \Drupal\xautoload\ClassFinder\ClassFinder::loadClass()
Callback for class loading. This will include ("require") the file found.
Parameters
string $class: The class to load.
Overrides ClassLoaderInterface::loadClass
File
- lib/
ClassFinder/ ClassFinder.php, line 373
Class
Namespace
Drupal\xautoload\ClassFinderCode
function loadClass($class) {
// Fix the behavior of some PHP versions that prepend '\\' to the class name.
if ('\\' === $class[0]) {
$class = substr($class, 1);
}
// First check if the literal class name is registered.
if (!empty($this->classes[$class])) {
foreach ($this->classes[$class] as $filepath => $true) {
if (file_exists($filepath)) {
require $filepath;
return TRUE;
}
}
}
// Check if the class has a namespace.
if (FALSE !== ($pos = strrpos($class, '\\'))) {
// Build the "logical path" based on PSR-4 replacement rules.
$logical_path = str_replace('\\', '/', $class) . '.php';
return $this->namespaceMap
->loadClass($class, $logical_path, $pos);
}
// Build the "logical path" based on PEAR replacement rules.
$pear_logical_path = str_replace('_', '/', $class) . '.php';
// Clean up surplus '/' resulting from duplicate underscores, or an
// underscore at the beginning of the class.
while (FALSE !== ($pos = strrpos('/' . $pear_logical_path, '//'))) {
$pear_logical_path[$pos] = '_';
}
// Check if the class has any underscore.
$pos = strrpos($pear_logical_path, '/');
return $this->prefixMap
->loadClass($class, $pear_logical_path, $pos);
}