You are here

class LoadClassGetFileInjectedApi in X Autoload 7.4

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

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 LoadClassGetFileInjectedApi

4 files declare their use of LoadClassGetFileInjectedApi
ApcClassLoader.php in lib/ClassLoader/ApcClassLoader.php
WinCacheClassLoader.php in lib/ClassLoader/WinCacheClassLoader.php
xautoload.early.lib.inc in ./xautoload.early.lib.inc
XCacheClassLoader.php in lib/ClassLoader/XCacheClassLoader.php

File

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

Namespace

Drupal\xautoload\ClassFinder\InjectedApi
View source
class LoadClassGetFileInjectedApi extends FindFileInjectedApi {

  /**
   * Suggest a file that, if the file exists,
   * has to declare the class we are looking for.
   * Only keep the class on success.
   *
   * @param string $file
   *   The file that is supposed to declare the class.
   *
   * @return bool
   *   TRUE, if the file exists.
   *   FALSE, otherwise.
   */
  function suggestFile($file) {
    if (file_exists($file)) {
      $this->file = $file;
      require $file;
      return TRUE;
    }
    else {
      return FALSE;
    }
  }

  /**
   * Same as suggestFile(), but skip the file_exists(),
   * assuming that we already know the file exists.
   *
   * This could make sense if a plugin already did the file_exists() check.
   *
   * @param string $file
   *   The file that is supposed to declare the class.
   *
   * @return bool
   *   TRUE, if the file was found - which is always.
   */
  function suggestFile_skipFileExists($file) {
    $this->file = $file;
    require $file;
    return TRUE;
  }

  /**
   * Same as suggestFile(), but assume that file_exists() returns TRUE.
   *
   * @param string $file
   *   The file that is supposed to declare the class.
   *
   * @return bool
   *   TRUE, if the file was found - which is always.
   */
  function suggestFile_checkNothing($file) {
    $this->file = $file;
    require $file;
    return TRUE;
  }

  /**
   * Same as suggestFile(), but check the full PHP include path.
   *
   * @param string $file
   *   The file that is supposed to declare the class.
   *
   * @return bool
   *   TRUE, if the file exists.
   *   FALSE, otherwise.
   */
  function suggestFile_checkIncludePath($file) {
    if (FALSE !== ($file = Util::findFileInIncludePath($file))) {
      $this->file = $file;
      require $file;
      return TRUE;
    }
  }

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

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

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

  /**
   * {@inheritdoc}
   */
  function claimPath($file) {
    if (file_exists($file)) {
      require $file;
      $this->file = $file;
      return TRUE;
    }
  }

}

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
FindFileInjectedApi::$file protected property The file that was found.
FindFileInjectedApi::getFile function When the process has finished, use this to return the result.
LoadClassGetFileInjectedApi::claimFile function Suggest a file that MUST exist, and if so, MUST declare the class we are looking for. Overrides FindFileInjectedApi::claimFile
LoadClassGetFileInjectedApi::claimPath function Suggest a file that MAY exist, and if so, MUST declare the class we are looking for. Overrides FindFileInjectedApi::claimPath
LoadClassGetFileInjectedApi::guessFile function Suggest a file that MUST exists, and that MAY declare the class we are looking for. Overrides FindFileInjectedApi::guessFile
LoadClassGetFileInjectedApi::guessPath function Suggest a file that MAY exist, and that MAY declare the class we are looking for. Overrides FindFileInjectedApi::guessPath
LoadClassGetFileInjectedApi::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 FindFileInjectedApi::suggestFile
LoadClassGetFileInjectedApi::suggestFile_checkIncludePath function Same as suggestFile(), but check the full PHP include path. Overrides FindFileInjectedApi::suggestFile_checkIncludePath
LoadClassGetFileInjectedApi::suggestFile_checkNothing function Same as suggestFile(), but assume that file_exists() returns TRUE. Overrides FindFileInjectedApi::suggestFile_checkNothing
LoadClassGetFileInjectedApi::suggestFile_skipFileExists function Same as suggestFile(), but skip the file_exists(), assuming that we already know the file exists. Overrides FindFileInjectedApi::suggestFile_skipFileExists