4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\ClassLoader;
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);
17 * A PSR-4 compatible class loader.
19 * See http://www.php-fig.org/psr/psr-4/
21 * @author Alexander M. Turek <me@derrabus.de>
23 * @deprecated since version 3.3, to be removed in 4.0.
27 private $prefixes = array();
30 * @param string $prefix
31 * @param string $baseDir
33 public function addPrefix($prefix, $baseDir)
35 $prefix = trim($prefix, '\\').'\\';
36 $baseDir = rtrim($baseDir, \DIRECTORY_SEPARATOR).\DIRECTORY_SEPARATOR;
37 $this->prefixes[] = array($prefix, $baseDir);
41 * @param string $class
45 public function findFile($class)
47 $class = ltrim($class, '\\');
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)) {
61 * @param string $class
65 public function loadClass($class)
67 $file = $this->findFile($class);
78 * Registers this instance as an autoloader.
80 * @param bool $prepend
82 public function register($prepend = false)
84 spl_autoload_register(array($this, 'loadClass'), true, $prepend);
88 * Removes this instance from the registered autoloaders.
90 public function unregister()
92 spl_autoload_unregister(array($this, 'loadClass'));