function ClassFinder::apiFindFile in X Autoload 7.4
Same name and namespace in other branches
- 7.5 src/ClassFinder/ClassFinder.php \Drupal\xautoload\ClassFinder\ClassFinder::apiFindFile()
Finds the path to the file where the class is defined.
Parameters
\Drupal\xautoload\ClassFinder\InjectedApi\InjectedApiInterface $api: API object with a suggestFile() method. We are supposed to call $api->suggestFile($file) with all suggestions we can find, until it returns TRUE. Once suggestFile() returns TRUE, we stop and return TRUE as well. The $file will be in the $api object, so we don't need to return it.
string $class: The name of the class, with all namespaces prepended. E.g. Some\Namespace\Some\Class
Return value
TRUE|NULL TRUE, if we found the file for the class. That is, if the $api->suggestFile($file) method returned TRUE one time. NULL, if we have no more suggestions.
Overrides ClassFinderInterface::apiFindFile
File
- lib/
ClassFinder/ ClassFinder.php, line 418
Class
Namespace
Drupal\xautoload\ClassFinderCode
function apiFindFile($api, $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 ($api
->suggestFile($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
->apiFindFile($api, $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
->apiFindFile($api, $pear_logical_path, $pos);
}