Added the Search API Synonym module to deal specifically with licence and license...
[yaffs-website] / vendor / symfony / class-loader / Psr4ClassLoader.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__.'\Psr4ClassLoader class is deprecated since Symfony 3.3 and will be removed in 4.0. Use Composer instead.', E_USER_DEPRECATED);
15
16 /**
17  * A PSR-4 compatible class loader.
18  *
19  * See http://www.php-fig.org/psr/psr-4/
20  *
21  * @author Alexander M. Turek <me@derrabus.de>
22  *
23  * @deprecated since version 3.3, to be removed in 4.0.
24  */
25 class Psr4ClassLoader
26 {
27     private $prefixes = array();
28
29     /**
30      * @param string $prefix
31      * @param string $baseDir
32      */
33     public function addPrefix($prefix, $baseDir)
34     {
35         $prefix = trim($prefix, '\\').'\\';
36         $baseDir = rtrim($baseDir, \DIRECTORY_SEPARATOR).\DIRECTORY_SEPARATOR;
37         $this->prefixes[] = array($prefix, $baseDir);
38     }
39
40     /**
41      * @param string $class
42      *
43      * @return string|null
44      */
45     public function findFile($class)
46     {
47         $class = ltrim($class, '\\');
48
49         foreach ($this->prefixes as list($currentPrefix, $currentBaseDir)) {
50             if (0 === strpos($class, $currentPrefix)) {
51                 $classWithoutPrefix = substr($class, \strlen($currentPrefix));
52                 $file = $currentBaseDir.str_replace('\\', \DIRECTORY_SEPARATOR, $classWithoutPrefix).'.php';
53                 if (file_exists($file)) {
54                     return $file;
55                 }
56             }
57         }
58     }
59
60     /**
61      * @param string $class
62      *
63      * @return bool
64      */
65     public function loadClass($class)
66     {
67         $file = $this->findFile($class);
68         if (null !== $file) {
69             require $file;
70
71             return true;
72         }
73
74         return false;
75     }
76
77     /**
78      * Registers this instance as an autoloader.
79      *
80      * @param bool $prepend
81      */
82     public function register($prepend = false)
83     {
84         spl_autoload_register(array($this, 'loadClass'), true, $prepend);
85     }
86
87     /**
88      * Removes this instance from the registered autoloaders.
89      */
90     public function unregister()
91     {
92         spl_autoload_unregister(array($this, 'loadClass'));
93     }
94 }