You are here

function FindFileInjectedApi::guessPath in X Autoload 7.4

Same name and namespace in other branches
  1. 7.5 src/ClassFinder/InjectedApi/FindFileInjectedApi.php \Drupal\xautoload\ClassFinder\InjectedApi\FindFileInjectedApi::guessPath()

Suggest a file that MAY exist, and that MAY declare the class we are looking for.

This is useful if a plugin already did the is_file() check by itself.

Parameters

string $file: The file that is supposed to declare the class.

Return value

boolean|NULL TRUE, if we are not interested in further candidates. FALSE|NULL, if we are interested in further candidates.

Overrides InjectedApiInterface::guessPath

1 method overrides FindFileInjectedApi::guessPath()
LoadClassGetFileInjectedApi::guessPath in lib/ClassFinder/InjectedApi/LoadClassGetFileInjectedApi.php
Suggest a file that MAY exist, and that MAY declare the class we are looking for.

File

lib/ClassFinder/InjectedApi/FindFileInjectedApi.php, line 123

Class

FindFileInjectedApi
To help testability, we use an injected API instead of just a return value. The injected API can be mocked to provide a mocked file_exists(), and to monitor all suggested candidates, not just the correct return value.

Namespace

Drupal\xautoload\ClassFinder\InjectedApi

Code

function guessPath($file) {
  if (file_exists($file)) {

    // The file must be included, or else we can't know if it defines the class.
    require_once $file;
    if (Util::classIsDefined($this->className)) {
      $this->file = $file;
      return TRUE;
    }
  }
}