Kaynağa Gözat

Merge pull request #173 from jeremyquinton/152

fixes #152
Matthew Weier O'Phinney 12 yıl önce
ebeveyn
işleme
16a6102bc7

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

@@ -128,7 +128,13 @@ class Zend_Loader_PluginLoader implements Zend_Loader_PluginLoader_Interface
         }
 
         $nsSeparator = (false !== strpos($prefix, '\\'))?'\\':'_';
-        return rtrim($prefix, $nsSeparator) . $nsSeparator;
+        $prefix = rtrim($prefix, $nsSeparator) . $nsSeparator;
+        //if $nsSeprator == "\" and the prefix ends in "_\" remove trailing \
+        //https://github.com/zendframework/zf1/issues/152
+        if(($nsSeparator == "\\") && (substr($prefix,-2) == "_\\")) {
+            $prefix = substr($prefix, 0, -1);
+        }
+        return $prefix;
     }
 
     /**

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

@@ -529,6 +529,28 @@ class Zend_Loader_PluginLoaderTest extends PHPUnit_Framework_TestCase
         }
         $this->assertEquals('Zfns\\Foo\\Bar', $className);
     }
+
+    /**
+     * @url https://github.com/zendframework/zf1/issues/152
+     */
+    public function testLoadClassesWithBackslashAndUnderscoreInName()
+    {
+        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\\Foo_', dirname(__FILE__) . '/_files/Zfns/Foo');
+
+        try {
+            $className = $loader->load('Demo');
+        } catch (Exception $e) {
+            $this->fail(sprintf("Failed loading helper with backslashes and underscores in name"));
+        }
+
+        $this->assertEquals('Zfns\Foo_Demo', $className);
+    }
 }
 
 // Call Zend_Loader_PluginLoaderTest::main() if this source file is executed directly.

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

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