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