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

Removes trailing path separator from userland option when assigned as a component for a resource type - fixes ZF-7501

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

+ 1 - 1
library/Zend/Loader/Autoloader/Resource.php

@@ -264,7 +264,7 @@ class Zend_Loader_Autoloader_Resource implements Zend_Loader_Autoloader_Interfac
             require_once 'Zend/Loader/Exception.php';
             throw new Zend_Loader_Exception('Invalid path specification provided; must be string');
         }
-        $this->_resourceTypes[$type]['path'] = $this->getBasePath() . '/' . $path;
+        $this->_resourceTypes[$type]['path'] = $this->getBasePath() . '/' . rtrim($path, '\/');
 
         $component = $this->_resourceTypes[$type]['namespace'];
         $this->_components[$component] = $this->_resourceTypes[$type]['path'];

+ 11 - 0
tests/Zend/Loader/Autoloader/ResourceTest.php

@@ -388,6 +388,17 @@ class Zend_Loader_Autoloader_ResourceTest extends PHPUnit_Framework_TestCase
         $loader = array_shift($loaders);
         $this->assertSame($this->loader, $loader);
     }
+
+    /**
+     * @group ZF-7501
+     */
+    public function testAutoloaderShouldTrimResourceTypePathsForTrailingPathSeparator()
+    {
+        $this->loader->addResourceType('models', 'models/', 'Model');
+        $resources = $this->loader->getResourceTypes();
+        $this->assertEquals($this->loader->getBasePath() . '/models', $resources['models']['path']);
+    }
+
 }
 
 if (PHPUnit_MAIN_METHOD == 'Zend_Loader_Autoloader_ResourceTest::main') {