Psr4ClassLoader.php in Zircon Profile 8
File
vendor/symfony/class-loader/Psr4ClassLoader.php
View source
<?php
namespace Symfony\Component\ClassLoader;
class Psr4ClassLoader {
private $prefixes = array();
public function addPrefix($prefix, $baseDir) {
$prefix = trim($prefix, '\\') . '\\';
$baseDir = rtrim($baseDir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
$this->prefixes[] = array(
$prefix,
$baseDir,
);
}
public function findFile($class) {
$class = ltrim($class, '\\');
foreach ($this->prefixes as $current) {
list($currentPrefix, $currentBaseDir) = $current;
if (0 === strpos($class, $currentPrefix)) {
$classWithoutPrefix = substr($class, strlen($currentPrefix));
$file = $currentBaseDir . str_replace('\\', DIRECTORY_SEPARATOR, $classWithoutPrefix) . '.php';
if (file_exists($file)) {
return $file;
}
}
}
}
public function loadClass($class) {
$file = $this
->findFile($class);
if (null !== $file) {
require $file;
return true;
}
return false;
}
public function register($prepend = false) {
spl_autoload_register(array(
$this,
'loadClass',
), true, $prepend);
}
public function unregister() {
spl_autoload_unregister(array(
$this,
'loadClass',
));
}
}