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