You are here

class MapClassLoader in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony/class-loader/MapClassLoader.php \Symfony\Component\ClassLoader\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

vendor/symfony/class-loader/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 bool $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 (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 (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.