You are here

class ProxyClassFinder in X Autoload 7.5

Same name and namespace in other branches
  1. 7.4 lib/ClassFinder/ProxyClassFinder.php \Drupal\xautoload\ClassFinder\ProxyClassFinder

A placeholder class finder. Used to postpone expensive operations until they are actually needed.

Hierarchy

Expanded class hierarchy of ProxyClassFinder

2 files declare their use of ProxyClassFinder
ServiceContainerInterface.php in src/DIC/ServiceContainerInterface.php
ServiceFactory.php in src/DIC/ServiceFactory.php

File

src/ClassFinder/ProxyClassFinder.php, line 12

Namespace

Drupal\xautoload\ClassFinder
View source
class ProxyClassFinder extends AbstractClassLoader implements ClassFinderInterface {

  /**
   * @var ExtendedClassFinderInterface
   *   The actual class finder.
   */
  protected $finder;

  /**
   * @var CacheMissObserverInterface[]
   *   Operations to run when the actual finder is initialized.
   */
  protected $cacheMissObservers = array();

  /**
   * @var bool
   */
  protected $initialized = FALSE;

  /**
   * @param ExtendedClassFinderInterface $finder
   *
   * @internal param \Drupal\xautoload\Adapter\DrupalExtensionAdapter $helper
   */
  function __construct($finder) {
    $this->finder = $finder;
  }

  /**
   * {@inheritdoc}
   */
  function loadClass($class) {
    $this
      ->initFinder();
    $this->finder
      ->loadClass($class);
  }

  /**
   * {@inheritdoc}
   */
  function apiFindFile($api, $class) {
    $this
      ->initFinder();
    return $this->finder
      ->apiFindFile($api, $class);
  }

  /**
   * @param CacheMissObserverInterface $observer
   */
  function observeFirstCacheMiss($observer) {
    if (!$this->initialized) {
      $this->cacheMissObservers[] = $observer;
    }
    else {
      $observer
        ->cacheMiss($this->finder);
    }
  }

  /**
   * @return ClassFinderInterface
   */
  function getFinder() {
    $this
      ->initFinder();
    return $this->finder;
  }

  /**
   * Initialize the finder and notify cache miss observers.
   */
  protected function initFinder() {
    if (!$this->initialized) {
      $this->initialized = TRUE;
      foreach ($this->cacheMissObservers as $operation) {
        $operation
          ->cacheMiss($this->finder);
      }
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AbstractClassLoader::register function Registers this instance as an autoloader. Overrides ClassLoaderInterface::register
AbstractClassLoader::unregister function Unregister from the spl autoload stack. Overrides ClassLoaderInterface::unregister
ProxyClassFinder::$cacheMissObservers protected property Operations to run when the actual finder is initialized.
ProxyClassFinder::$finder protected property The actual class finder.
ProxyClassFinder::$initialized protected property
ProxyClassFinder::apiFindFile function Finds the path to the file where the class is defined. Overrides ClassFinderInterface::apiFindFile
ProxyClassFinder::getFinder function
ProxyClassFinder::initFinder protected function Initialize the finder and notify cache miss observers.
ProxyClassFinder::loadClass function Callback for class loading. This will include ("require") the file found. Overrides ClassLoaderInterface::loadClass
ProxyClassFinder::observeFirstCacheMiss function
ProxyClassFinder::__construct function @internal param \Drupal\xautoload\Adapter\DrupalExtensionAdapter $helper