annotate vendor/symfony/class-loader/MapClassLoader.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 129ea1e6d783
children
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 /*
Chris@0 4 * This file is part of the Symfony package.
Chris@0 5 *
Chris@0 6 * (c) Fabien Potencier <fabien@symfony.com>
Chris@0 7 *
Chris@0 8 * For the full copyright and license information, please view the LICENSE
Chris@0 9 * file that was distributed with this source code.
Chris@0 10 */
Chris@0 11
Chris@0 12 namespace Symfony\Component\ClassLoader;
Chris@0 13
Chris@14 14 @trigger_error('The '.__NAMESPACE__.'\MapClassLoader class is deprecated since Symfony 3.3 and will be removed in 4.0. Use Composer instead.', E_USER_DEPRECATED);
Chris@14 15
Chris@0 16 /**
Chris@0 17 * A class loader that uses a mapping file to look up paths.
Chris@0 18 *
Chris@0 19 * @author Fabien Potencier <fabien@symfony.com>
Chris@14 20 *
Chris@14 21 * @deprecated since version 3.3, to be removed in 4.0.
Chris@0 22 */
Chris@0 23 class MapClassLoader
Chris@0 24 {
Chris@17 25 private $map = [];
Chris@0 26
Chris@0 27 /**
Chris@0 28 * @param array $map A map where keys are classes and values the absolute file path
Chris@0 29 */
Chris@0 30 public function __construct(array $map)
Chris@0 31 {
Chris@0 32 $this->map = $map;
Chris@0 33 }
Chris@0 34
Chris@0 35 /**
Chris@0 36 * Registers this instance as an autoloader.
Chris@0 37 *
Chris@0 38 * @param bool $prepend Whether to prepend the autoloader or not
Chris@0 39 */
Chris@0 40 public function register($prepend = false)
Chris@0 41 {
Chris@17 42 spl_autoload_register([$this, 'loadClass'], true, $prepend);
Chris@0 43 }
Chris@0 44
Chris@0 45 /**
Chris@0 46 * Loads the given class or interface.
Chris@0 47 *
Chris@0 48 * @param string $class The name of the class
Chris@0 49 */
Chris@0 50 public function loadClass($class)
Chris@0 51 {
Chris@0 52 if (isset($this->map[$class])) {
Chris@0 53 require $this->map[$class];
Chris@0 54 }
Chris@0 55 }
Chris@0 56
Chris@0 57 /**
Chris@0 58 * Finds the path to the file where the class is defined.
Chris@0 59 *
Chris@0 60 * @param string $class The name of the class
Chris@0 61 *
Chris@0 62 * @return string|null The path, if found
Chris@0 63 */
Chris@0 64 public function findFile($class)
Chris@0 65 {
Chris@0 66 if (isset($this->map[$class])) {
Chris@0 67 return $this->map[$class];
Chris@0 68 }
Chris@0 69 }
Chris@0 70 }