Mercurial > hg > isophonics-drupal-site
comparison vendor/symfony/class-loader/MapClassLoader.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children | 1fec387a4317 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
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 /** | |
15 * A class loader that uses a mapping file to look up paths. | |
16 * | |
17 * @author Fabien Potencier <fabien@symfony.com> | |
18 */ | |
19 class MapClassLoader | |
20 { | |
21 private $map = array(); | |
22 | |
23 /** | |
24 * Constructor. | |
25 * | |
26 * @param array $map A map where keys are classes and values the absolute file path | |
27 */ | |
28 public function __construct(array $map) | |
29 { | |
30 $this->map = $map; | |
31 } | |
32 | |
33 /** | |
34 * Registers this instance as an autoloader. | |
35 * | |
36 * @param bool $prepend Whether to prepend the autoloader or not | |
37 */ | |
38 public function register($prepend = false) | |
39 { | |
40 spl_autoload_register(array($this, 'loadClass'), true, $prepend); | |
41 } | |
42 | |
43 /** | |
44 * Loads the given class or interface. | |
45 * | |
46 * @param string $class The name of the class | |
47 */ | |
48 public function loadClass($class) | |
49 { | |
50 if (isset($this->map[$class])) { | |
51 require $this->map[$class]; | |
52 } | |
53 } | |
54 | |
55 /** | |
56 * Finds the path to the file where the class is defined. | |
57 * | |
58 * @param string $class The name of the class | |
59 * | |
60 * @return string|null The path, if found | |
61 */ | |
62 public function findFile($class) | |
63 { | |
64 if (isset($this->map[$class])) { | |
65 return $this->map[$class]; | |
66 } | |
67 } | |
68 } |