You are here

class LoadClassInjectedAPI in X Autoload 7.4

Same name and namespace in other branches
  1. 7.5 src/ClassFinder/InjectedApi/LoadClassInjectedAPI.php \Drupal\xautoload\ClassFinder\InjectedApi\LoadClassInjectedAPI

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.

Hierarchy

Expanded class hierarchy of LoadClassInjectedAPI

2 files declare their use of LoadClassInjectedAPI
GenericPrefixMap.php in lib/ClassFinder/GenericPrefixMap.php
xautoload.early.lib.inc in ./xautoload.early.lib.inc

File

lib/ClassFinder/InjectedApi/LoadClassInjectedAPI.php, line 12

Namespace

Drupal\xautoload\ClassFinder\InjectedApi
View source
class LoadClassInjectedAPI extends AbstractInjectedApi {

  /**
   * {@inheritdoc}
   */
  function suggestFile($file) {
    if (file_exists($file)) {
      require $file;
      return TRUE;
    }
    else {
      return FALSE;
    }
  }

  /**
   * {@inheritdoc}
   */
  function suggestFile_skipFileExists($file) {
    require $file;
    return TRUE;
  }

  /**
   * {@inheritdoc}
   */
  function suggestFile_checkNothing($file) {
    require $file;
    return TRUE;
  }

  /**
   * {@inheritdoc}
   */
  function suggestFile_checkIncludePath($file) {
    if (FALSE !== ($file = Util::findFileInIncludePath($file))) {
      require $file;
      return TRUE;
    }
    else {
      return FALSE;
    }
  }

  /**
   * {@inheritdoc}
   */
  function guessFile($file) {
    require_once $file;
    return Util::classIsDefined($this->className);
  }

  /**
   * {@inheritdoc}
   */
  function guessPath($file) {
    if (file_exists($file)) {
      require_once $file;
      return Util::classIsDefined($this->className);
    }
    else {
      return FALSE;
    }
  }

  /**
   * {@inheritdoc}
   */
  function claimFile($file) {
    require $file;
    return TRUE;
  }

  /**
   * {@inheritdoc}
   */
  function claimPath($file) {
    if (file_exists($file)) {
      require $file;
      return TRUE;
    }
    else {
      return FALSE;
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AbstractInjectedApi::$className protected property The class name to look for. Set in the constructor.
AbstractInjectedApi::forceAutoload static function Dummy method to force autoloading this class (or an ancestor).
AbstractInjectedApi::getClass function Get the name of the class we are looking for. Overrides InjectedApiInterface::getClass
AbstractInjectedApi::is_dir function This is done in the injected api object, so we can easily provide a mock implementation. Overrides InjectedApiInterface::is_dir
AbstractInjectedApi::__construct function 1
LoadClassInjectedAPI::claimFile function Suggest a file that MUST exist, and if so, MUST declare the class we are looking for. Overrides InjectedApiInterface::claimFile
LoadClassInjectedAPI::claimPath function Suggest a file that MAY exist, and if so, MUST declare the class we are looking for. Overrides InjectedApiInterface::claimPath
LoadClassInjectedAPI::guessFile function Suggest a file that MUST exists, and that MAY declare the class we are looking for. Overrides InjectedApiInterface::guessFile
LoadClassInjectedAPI::guessPath function Suggest a file that MAY exist, and that MAY declare the class we are looking for. Overrides InjectedApiInterface::guessPath
LoadClassInjectedAPI::suggestFile function Suggest a file that, if the file exists, has to declare the class we are looking for. Only keep the class on success. Overrides InjectedApiInterface::suggestFile
LoadClassInjectedAPI::suggestFile_checkIncludePath function Same as suggestFile(), but check the full PHP include path. Overrides InjectedApiInterface::suggestFile_checkIncludePath
LoadClassInjectedAPI::suggestFile_checkNothing function Same as suggestFile(), but assume that file_exists() returns TRUE. Overrides InjectedApiInterface::suggestFile_checkNothing
LoadClassInjectedAPI::suggestFile_skipFileExists function Same as suggestFile(), but skip the file_exists(), assuming that we already know the file exists. Overrides InjectedApiInterface::suggestFile_skipFileExists