Permalink
Browse files

Method add() now checks to see if prefix path has already been added,…

… and new method Loader::addClasses() to merge new class list with old one)
  • Loading branch information...
1 parent 5902966 commit 1a1b97b69e995dd28d664823771931531d3deff2 @pmjones pmjones committed Sep 21, 2012
Showing with 48 additions and 1 deletion.
  1. +20 −1 src/Aura/Autoload/Loader.php
  2. +28 −0 tests/Aura/Autoload/LoaderTest.php
@@ -175,7 +175,11 @@ public function unregister()
public function add($prefix, $paths)
{
foreach ((array) $paths as $path) {
- $this->paths[$prefix][] = rtrim($path, DIRECTORY_SEPARATOR);
+ $path = rtrim($path, DIRECTORY_SEPARATOR);
+ if (! in_array($prefix, $this->paths)) {
+ // has not been added yet, so add it
+ $this->paths[$prefix][] = $path;
+ }
}
}
@@ -254,6 +258,21 @@ public function setClasses(array $classes)
/**
*
+ * Adds file paths for class names to the existing exact mappings.
+ *
+ * @param array $classes An array of class-to-file mappings where the key
+ * is the class name and the value is the file path.
+ *
+ * @return void
+ *
+ */
+ public function addClasses(array $classes)
+ {
+ $this->classes = array_merge($this->classes, $classes);
+ }
+
+ /**
+ *
* Returns the list of exact class names and their paths.
*
* @return array
@@ -233,6 +233,34 @@ public function testSetClasses()
$this->assertSame($expect, $actual);
}
+ public function testAddClasses()
+ {
+ $autoloader = new Loader;
+
+ $series_1 = [
+ 'FooBar' => '/path/to/FooBar.php',
+ 'BazDib' => '/path/to/BazDib.php',
+ ];
+
+ $series_2 = [
+ 'ZimGir' => '/path/to/ZimGir.php',
+ 'IrkDoom' => '/path/to/IrkDoom.php',
+ ];
+
+ $expect = [
+ 'FooBar' => '/path/to/FooBar.php',
+ 'BazDib' => '/path/to/BazDib.php',
+ 'ZimGir' => '/path/to/ZimGir.php',
+ 'IrkDoom' => '/path/to/IrkDoom.php',
+ ];
+
+ $autoloader->addClasses($series_1);
+ $autoloader->addClasses($series_2);
+
+ $actual = $autoloader->getClasses();
+ $this->assertSame($expect, $actual);
+ }
+
public function testSetPaths()
{
$class1 = 'Aura\Autoload\Foo\MockAutoloadCliClass';

0 comments on commit 1a1b97b

Please sign in to comment.