- Adding prefix option to ClassLoader::add()

- Adding set method to ClassLoader for overwriting
main
Joe Holdcroft 12 years ago
parent de3188ca7d
commit e74223470a

@ -75,12 +75,13 @@ 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) { foreach ((array) $paths as $path) {
@ -90,15 +91,39 @@ class ClassLoader
return; return;
} }
if (isset($this->prefixes[$prefix])) { if (isset($this->prefixes[$prefix])) {
$this->prefixes[$prefix] = array_merge( if ($prepend) {
$this->prefixes[$prefix], $this->prefixes[$prefix] = array_merge(
(array) $paths (array) $paths,
); $this->prefixes[$prefix]
);
}
else {
$this->prefixes[$prefix] = array_merge(
$this->prefixes[$prefix],
(array) $paths
);
}
} else { } else {
$this->prefixes[$prefix] = (array) $paths; $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) $path;
return;
}
$this->prefixes[$prefix] = (array) $paths;
}
/** /**
* Turns on searching the include path for class files. * Turns on searching the include path for class files.
* *

Loading…
Cancel
Save