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

ZF-7350: allow using namespaced classes with PluginLoader

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@21169 44c647ce-9c0f-0410-b52a-842ac1e357ba
matthew 16 лет назад
Родитель
Сommit
4e001f9519
2 измененных файлов с 27 добавлено и 0 удалено
  1. 6 0
      library/Zend/Loader/PluginLoader.php
  2. 21 0
      tests/Zend/Loader/PluginLoaderTest.php

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

@@ -126,6 +126,12 @@ class Zend_Loader_PluginLoader implements Zend_Loader_PluginLoader_Interface
         if($prefix == "") {
             return $prefix;
         }
+
+        $last = strlen($prefix) - 1;
+        if ($prefix{$last} == '\\') {
+            return $prefix;
+        }
+
         return rtrim($prefix, '_') . '_';
     }
 

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

@@ -479,6 +479,27 @@ class Zend_Loader_PluginLoaderTest extends PHPUnit_Framework_TestCase
         $classPath = $loader->getClassPath('DeclareVars');
         $this->assertContains($expected, $classPath);
     }
+
+    /**
+     * @group ZF-7350
+     */
+    public function testPrefixesEndingInBackslashDenoteNamespacedClasses()
+    {
+        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');
+        } catch (Exception $e) {
+            $paths = $loader->getPaths();
+            $this->fail(sprintf("Failed loading helper; paths: %s", var_export($paths, 1)));
+        }
+        $this->assertEquals('Zfns\\Foo', $className);
+        $this->assertEquals('Zfns\\Foo', $loader->getClassName('Foo'));
+    }
 }
 
 // Call Zend_Loader_PluginLoaderTest::main() if this source file is executed directly.