Ver código fonte

ZF-6134 - Committed patch by Matthew Turland, preventing the same path from being loaded more than once per class path in the plugin loader (thereby removing a significant performance drain)

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@18206 44c647ce-9c0f-0410-b52a-842ac1e357ba
beberlei 16 anos atrás
pai
commit
a79f781297

+ 6 - 1
library/Zend/Loader/PluginLoader.php

@@ -149,7 +149,12 @@ class Zend_Loader_PluginLoader implements Zend_Loader_PluginLoader_Interface
         if ($this->_useStaticRegistry) {
             self::$_staticPrefixToPaths[$this->_useStaticRegistry][$prefix][] = $path;
         } else {
-            $this->_prefixToPaths[$prefix][] = $path;
+            if (!isset($this->_prefixToPaths[$prefix])) {
+                $this->_prefixToPaths[$prefix] = array();
+            }
+            if (!in_array($path, $this->_prefixToPaths[$prefix])) {
+                $this->_prefixToPaths[$prefix][] = $path;
+            }
         }
         return $this;
     }

+ 11 - 0
tests/Zend/Loader/PluginLoaderTest.php

@@ -113,6 +113,17 @@ class Zend_Loader_PluginLoaderTest extends PHPUnit_Framework_TestCase
         $this->assertEquals(2, count($paths['Zend_Loader_']));
     }
 
+    public function testAddPrefixPathMultipleTimes()
+    {
+        $loader = new Zend_Loader_PluginLoader();
+        $loader->addPrefixPath('Zend_Loader', $this->libPath . '/Zend/Loader')
+               ->addPrefixPath('Zend_Loader', $this->libPath . '/Zend/Loader');
+        $paths = $loader->getPaths();
+
+        $this->assertType('array', $paths);
+        $this->assertEquals(1, count($paths['Zend_Loader_']));
+    }
+
     public function testAddPrefixPathStatically()
     {
         $this->key = 'foobar';