function GenericPrefixMap::apiFindFile in X Autoload 7.5
Same name and namespace in other branches
- 7.4 lib/ClassFinder/GenericPrefixMap.php \Drupal\xautoload\ClassFinder\GenericPrefixMap::apiFindFile()
Find the file for a class that in PSR-0 or PEAR would be in $psr_0_root . '/' . $path_fragment . $path_suffix
Parameters
InjectedApiInterface $api:
string $logical_path: Class name translated into a logical path, either with PSR-4 or with PEAR translation rules.
int|bool $lastpos: Position of the last directory separator in $logical_path. FALSE, if there is no directory separator in $logical_path.
Return value
bool|NULL TRUE, if the class was found.
File
- src/
ClassFinder/ GenericPrefixMap.php, line 198
Class
- GenericPrefixMap
- Helper class for the class finder. This is not part of ClassFinder, because we want to use the same logic for namespaces (PSR-0) and prefixes (PEAR).
Namespace
Drupal\xautoload\ClassFinderCode
function apiFindFile($api, $logical_path, $lastpos) {
$pos = $lastpos;
while (TRUE) {
$logical_base_path = FALSE === $pos ? '' : substr($logical_path, 0, $pos + 1);
if (isset($this->paths[$logical_base_path])) {
foreach ($this->paths[$logical_base_path] as $dir => $behavior) {
if ($behavior instanceof DefaultDirectoryBehavior) {
// PSR-4 and PEAR
if ($api
->suggestFile($dir . substr($logical_path, $pos + 1))) {
return TRUE;
}
}
elseif ($behavior instanceof Psr0DirectoryBehavior) {
// PSR-0
if ($api
->suggestFile($dir . substr($logical_path, $pos + 1, $lastpos - $pos) . str_replace('_', '/', substr($logical_path, $lastpos + 1)))) {
return TRUE;
}
}
elseif ($behavior instanceof xautoload_FinderPlugin_Interface) {
// Legacy "FinderPlugin".
if ($behavior
->findFile($api, $logical_base_path, substr($logical_path, $pos + 1), $dir)) {
return TRUE;
}
}
}
}
// Continue with parent fragment.
if (FALSE === $pos) {
return NULL;
}
$pos = strrpos($logical_base_path, '/', -2);
}
return NULL;
}