You are here

class ProxyClassFinder in X Autoload 7.4

Same name and namespace in other branches
  1. 7.5 src/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 lib/DIC/ServiceContainerInterface.php
ServiceFactory.php in lib/DIC/ServiceFactory.php

File

lib/ClassFinder/ProxyClassFinder.php, line 13

Namespace

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

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

  /**
   * @var DrupalExtensionAdapter
   */
  protected $helper;

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

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

  /**
   * @param ExtendedClassFinderInterface $finder
   * @param DrupalExtensionAdapter $helper
   */
  function __construct($finder, $helper) {
    $this->finder = $finder;
    $this->helper = $helper;
  }

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

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

  /**
   * @param FinderOperationInterface $operation
   */
  function onFinderInit($operation) {
    if (!$this->initialized) {
      $this->scheduledOperations[] = $operation;
    }
    else {
      $operation
        ->operateOnFinder($this->finder, $this->helper);
    }
  }

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

  /**
   * Initialize the finder and run scheduled operations.
   */
  protected function initFinder() {
    if (!$this->initialized) {
      foreach ($this->scheduledOperations as $operation) {
        $operation
          ->operateOnFinder($this->finder, $this->helper);
      }
      $this->initialized = TRUE;
    }
  }

}

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::$finder protected property The actual class finder.
ProxyClassFinder::$helper protected property
ProxyClassFinder::$initialized protected property
ProxyClassFinder::$scheduledOperations protected property Operations to run when the actual finder is initialized.
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 run scheduled operations.
ProxyClassFinder::loadClass function Callback for class loading. This will include ("require") the file found. Overrides ClassLoaderInterface::loadClass
ProxyClassFinder::onFinderInit function
ProxyClassFinder::__construct function