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

ZF-10836 Zend_Loader_Autoloader_Resource::setOptions() should set namespace before resourceTypes - committing patch for Adam Lundrigan

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@23567 44c647ce-9c0f-0410-b52a-842ac1e357ba
mjh_ca 15 лет назад
Родитель
Сommit
66f6b127eb

+ 6 - 0
library/Zend/Loader/Autoloader/Resource.php

@@ -206,6 +206,12 @@ class Zend_Loader_Autoloader_Resource implements Zend_Loader_Autoloader_Interfac
      */
     public function setOptions(array $options)
     {
+        // Set namespace first, see ZF-10836
+        if (isset($options['namespace'])) {
+            $this->setNamespace($options['namespace']);
+            unset($options['namespace']);
+        }
+
         $methods = get_class_methods($this);
         foreach ($options as $key => $value) {
             $method = 'set' . ucfirst($key);

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

@@ -419,6 +419,41 @@ class Zend_Loader_Autoloader_ResourceTest extends PHPUnit_Framework_TestCase
         $path = $this->loader->autoload('Something_Totally_Wrong');
         $this->assertFalse($path);
     }
+
+    /**
+     * @group ZF-10836
+     */
+    public function testConstructorAcceptsNamespaceKeyInAnyOrder()
+    {
+        // namespace is after resourceTypes - fails in ZF 1.11.1
+        $data = array(
+            'basePath'      => 'path/to/some/directory',
+            'resourceTypes' => array(
+                'acl' => array(
+                    'path'      => 'acls/',
+                    'namespace' => 'Acl',
+                )
+            ),
+            'namespace'     => 'My'
+        );
+        $loader1 = new Zend_Loader_Autoloader_Resource($data);
+
+        // namespace is defined before resourceTypes - always worked as expected
+        $data = array(
+            'basePath'      => 'path/to/some/directory',
+            'namespace'     => 'My',
+            'resourceTypes' => array(
+                'acl' => array(
+                    'path'      => 'acls/',
+                    'namespace' => 'Acl',
+                )
+            )
+        );
+        $loader2 = new Zend_Loader_Autoloader_Resource($data);
+
+        // Check that autoloaders are configured the same
+        $this->assertEquals($loader1, $loader2);
+    }
 }
 
 if (PHPUnit_MAIN_METHOD == 'Zend_Loader_Autoloader_ResourceTest::main') {