1
0
Fork 0

Merge remote-tracking branch 'joeholdcroft/autoload-namespace-prepend'

pull/1497/merge
Jordi Boggiano 2013-01-17 17:14:27 +01:00
commit 1bd01a8b0b
1 changed files with 43 additions and 9 deletions

View File

@ -75,30 +75,64 @@ class ClassLoader
} }
/** /**
* Registers a set of classes * Registers a set of classes, merging with any others previously set.
* *
* @param string $prefix The classes prefix * @param string $prefix The classes prefix
* @param array|string $paths The location(s) of the classes * @param array|string $paths The location(s) of the classes
* @param bool $prepend Prepend the location(s)
*/ */
public function add($prefix, $paths) public function add($prefix, $paths, $prepend = false)
{ {
if (!$prefix) { if (!$prefix) {
foreach ((array) $paths as $path) { if ($prepend) {
$this->fallbackDirs[] = $path; $this->fallbackDirs = array_merge(
(array) $paths,
$this->fallbackDirs
);
}
else {
$this->fallbackDirs = array_merge(
$this->fallbackDirs,
(array) $paths
);
} }
return; return;
} }
if (isset($this->prefixes[$prefix])) { if (!isset($this->prefixes[$prefix])) {
$this->prefixes[$prefix] = (array) $paths;
return;
}
if ($prepend) {
$this->prefixes[$prefix] = array_merge(
(array) $paths,
$this->prefixes[$prefix]
);
} else {
$this->prefixes[$prefix] = array_merge( $this->prefixes[$prefix] = array_merge(
$this->prefixes[$prefix], $this->prefixes[$prefix],
(array) $paths (array) $paths
); );
} else {
$this->prefixes[$prefix] = (array) $paths;
} }
} }
/**
* Registers a set of classes, replacing any others previously set.
*
* @param string $prefix The classes prefix
* @param array|string $paths The location(s) of the classes
*/
public function set($prefix, $paths)
{
if (!$prefix) {
$this->fallbackDirs = (array) $paths;
return;
}
$this->prefixes[$prefix] = (array) $paths;
}
/** /**
* Turns on searching the include path for class files. * Turns on searching the include path for class files.
* *