class MapClassLoader

A class loader that uses a mapping file to look up paths.

@author Fabien Potencier <fabien@symfony.com>

Hierarchy

Expanded class hierarchy of MapClassLoader

File

drupal/core/vendor/symfony/class-loader/Symfony/Component/ClassLoader/MapClassLoader.php, line 19

Namespace

Symfony\Component\ClassLoader
View source
class MapClassLoader {
  private $map = array();

  /**
   * Constructor.
   *
   * @param array $map A map where keys are classes and values the absolute file path
   */
  public function __construct(array $map) {
    $this->map = $map;
  }

  /**
   * Registers this instance as an autoloader.
   *
   * @param Boolean $prepend Whether to prepend the autoloader or not
   */
  public function register($prepend = false) {
    spl_autoload_register(array(
      $this,
      'loadClass',
    ), true, $prepend);
  }

  /**
   * Loads the given class or interface.
   *
   * @param string $class The name of the class
   */
  public function loadClass($class) {
    if ('\\' === $class[0]) {
      $class = substr($class, 1);
    }
    if (isset($this->map[$class])) {
      require $this->map[$class];
    }
  }

  /**
   * Finds the path to the file where the class is defined.
   *
   * @param string $class The name of the class
   *
   * @return string|null The path, if found
   */
  public function findFile($class) {
    if ('\\' === $class[0]) {
      $class = substr($class, 1);
    }
    if (isset($this->map[$class])) {
      return $this->map[$class];
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
MapClassLoader::$map private property
MapClassLoader::findFile public function Finds the path to the file where the class is defined.
MapClassLoader::loadClass public function Loads the given class or interface.
MapClassLoader::register public function Registers this instance as an autoloader.
MapClassLoader::__construct public function Constructor.