1
0
Fork 0

Allow multiple fallback dirs

pull/171/head
Jordi Boggiano 2011-12-21 16:56:18 +01:00
parent 94a8e8809c
commit 2c367e7f39
1 changed files with 12 additions and 9 deletions

View File

@ -40,13 +40,18 @@ namespace Composer\Autoload;
class ClassLoader
{
private $prefixes = array();
private $fallbackDir;
private $fallbackDirs = array();
public function getPrefixes()
{
return $this->prefixes;
}
public function getFallbackDirs()
{
return $this->fallbackDirs;
}
/**
* Registers a set of classes
*
@ -56,7 +61,7 @@ class ClassLoader
public function add($prefix, $paths)
{
if (!$prefix) {
$this->fallbackDir = is_array($paths) ? $paths[0] : $paths;
$this->fallbackDirs = (array) $paths;
return;
}
if (isset($this->prefixes[$prefix])) {
@ -121,18 +126,16 @@ class ClassLoader
foreach ($this->prefixes as $prefix => $dirs) {
foreach ($dirs as $dir) {
if (0 === strpos($class, $prefix)) {
$file = $dir . $classPath;
if (file_exists($file)) {
return $file;
if (file_exists($dir . $classPath)) {
return $dir . $classPath;
}
}
}
}
if ($this->fallbackDir) {
$file = $this->fallbackDir . $classPath;
if (file_exists($file)) {
return $file;
foreach ($this->fallbackDirs as $dir) {
if (file_exists($dir . $classPath)) {
return $dir . $classPath;
}
}
}