Chris@0: Chris@0: * Chris@0: * For the full copyright and license information, please view the LICENSE Chris@0: * file that was distributed with this source code. Chris@0: */ Chris@0: Chris@0: namespace Symfony\Component\ClassLoader; Chris@0: Chris@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); Chris@14: Chris@0: /** Chris@0: * A PSR-4 compatible class loader. Chris@0: * Chris@0: * See http://www.php-fig.org/psr/psr-4/ Chris@0: * Chris@0: * @author Alexander M. Turek Chris@14: * Chris@14: * @deprecated since version 3.3, to be removed in 4.0. Chris@0: */ Chris@0: class Psr4ClassLoader Chris@0: { Chris@17: private $prefixes = []; Chris@0: Chris@0: /** Chris@0: * @param string $prefix Chris@0: * @param string $baseDir Chris@0: */ Chris@0: public function addPrefix($prefix, $baseDir) Chris@0: { Chris@0: $prefix = trim($prefix, '\\').'\\'; Chris@17: $baseDir = rtrim($baseDir, \DIRECTORY_SEPARATOR).\DIRECTORY_SEPARATOR; Chris@17: $this->prefixes[] = [$prefix, $baseDir]; Chris@0: } Chris@0: Chris@0: /** Chris@0: * @param string $class Chris@0: * Chris@0: * @return string|null Chris@0: */ Chris@0: public function findFile($class) Chris@0: { Chris@0: $class = ltrim($class, '\\'); Chris@0: Chris@0: foreach ($this->prefixes as list($currentPrefix, $currentBaseDir)) { Chris@0: if (0 === strpos($class, $currentPrefix)) { Chris@17: $classWithoutPrefix = substr($class, \strlen($currentPrefix)); Chris@17: $file = $currentBaseDir.str_replace('\\', \DIRECTORY_SEPARATOR, $classWithoutPrefix).'.php'; Chris@0: if (file_exists($file)) { Chris@0: return $file; Chris@0: } Chris@0: } Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * @param string $class Chris@0: * Chris@0: * @return bool Chris@0: */ Chris@0: public function loadClass($class) Chris@0: { Chris@0: $file = $this->findFile($class); Chris@0: if (null !== $file) { Chris@0: require $file; Chris@0: Chris@0: return true; Chris@0: } Chris@0: Chris@0: return false; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Registers this instance as an autoloader. Chris@0: * Chris@0: * @param bool $prepend Chris@0: */ Chris@0: public function register($prepend = false) Chris@0: { Chris@17: spl_autoload_register([$this, 'loadClass'], true, $prepend); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Removes this instance from the registered autoloaders. Chris@0: */ Chris@0: public function unregister() Chris@0: { Chris@17: spl_autoload_unregister([$this, 'loadClass']); Chris@0: } Chris@0: }