You are here

function xautoload_ClassFinder_Prefix::findFile in X Autoload 7.2

Same name and namespace in other branches
  1. 7.3 lib/ClassFinder/Prefix.php \xautoload_ClassFinder_Prefix::findFile()

Finds the path to the file where the class is defined.

Parameters

xautoload_InjectedAPI_findFile $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 xautoload_ClassFinder_Interface::findFile

1 call to xautoload_ClassFinder_Prefix::findFile()
xautoload_ClassFinder_NamespaceOrPrefix::findFile in lib/ClassFinder/NamespaceOrPrefix.php
Finds the path to the file where the class is defined.
1 method overrides xautoload_ClassFinder_Prefix::findFile()
xautoload_ClassFinder_NamespaceOrPrefix::findFile in lib/ClassFinder/NamespaceOrPrefix.php
Finds the path to the file where the class is defined.

File

lib/ClassFinder/Prefix.php, line 133

Class

xautoload_ClassFinder_Prefix

Code

function findFile($api, $class) {

  // First check if the literal class name is registered.
  if (isset($this->classes[$class])) {
    if ($api
      ->suggestFile($this->classes[$class])) {
      return TRUE;
    }
  }
  if ($class[0] === '_') {

    // We don't autoload classes that begin with '_'.
    return;
  }
  if (FALSE !== ($pos = strrpos($class, '_'))) {

    // Class does contain one or more '_' symbols.
    // Determine the canonical path.
    $path = str_replace('_', DIRECTORY_SEPARATOR, $class) . '.php';

    // Loop through all '/', backwards.
    do {
      $first_part = substr($path, 0, $pos + 1);
      $second_part = substr($path, $pos + 1);
      if ($this->prefixMap
        ->findFile_nested($api, $first_part, $second_part)) {
        return TRUE;
      }
      $pos = strrpos($first_part, DIRECTORY_SEPARATOR, -2);
    } while (FALSE !== $pos);

    // Check if anything is registered for '' prefix.
    if ($this->prefixMap
      ->findFile_nested($api, '', $path)) {
      return TRUE;
    }
  }
}