2
0
Просмотр исходного кода

ZF-11330: Zend_Loader_PluginLoader does not properly handle 5.3 namespaces

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@24877 44c647ce-9c0f-0410-b52a-842ac1e357ba
adamlundrigan 13 лет назад
Родитель
Сommit
d533d34f57

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

@@ -368,7 +368,11 @@ class Zend_Loader_PluginLoader implements Zend_Loader_PluginLoader_Interface
 
         $registry  = array_reverse($registry, true);
         $found     = false;
-        $classFile = str_replace('_', DIRECTORY_SEPARATOR, $name) . '.php';
+        if (false !== strpos($name, '\\')) {
+            $classFile = str_replace('\\', DIRECTORY_SEPARATOR, $name) . '.php';
+        } else {
+            $classFile = str_replace('_', DIRECTORY_SEPARATOR, $name) . '.php';
+        }
         $incFile   = self::getIncludeFileCache();
         foreach ($registry as $prefix => $paths) {
             $className = $prefix . $name;

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

@@ -510,6 +510,25 @@ class Zend_Loader_PluginLoaderTest extends PHPUnit_Framework_TestCase
         }
         $this->assertEquals(1, count($loader->getPaths('My_Namespace_')));
     }
+
+    /**
+     * @group ZF-11330
+     */
+    public function testLoadClassesWithBackslashInName()
+    {
+        if (version_compare(PHP_VERSION, '5.3.0', '<')) {
+            $this->markTestSkipped(__CLASS__ . '::' . __METHOD__ . ' requires PHP 5.3.0 or greater');
+            return;
+        }
+        $loader = new Zend_Loader_PluginLoader(array());
+        $loader->addPrefixPath('Zfns\\', dirname(__FILE__) . '/_files/Zfns');
+        try {
+            $className = $loader->load('Foo\\Bar');
+        } catch (Exception $e) {
+            $this->fail(sprintf("Failed loading helper with backslashes in name"));
+        }
+        $this->assertEquals('Zfns\\Foo\\Bar', $className);
+    }
 }
 
 // Call Zend_Loader_PluginLoaderTest::main() if this source file is executed directly.

+ 7 - 0
tests/Zend/Loader/_files/Zfns/Foo/Bar.php

@@ -0,0 +1,7 @@
+<?php
+namespace Zfns\Foo;
+
+class Bar
+{
+}
+