Browse Source

[DependencyInjection] fixed conversion of DOM to array when DOM includes multiple elements with the same name

Kris Wallsmith 15 năm trước cách đây
mục cha
commit
e63ff6e04b

+ 1 - 1
src/Symfony/Components/DependencyInjection/Loader/XmlFileLoader.php

@@ -374,7 +374,7 @@ EOF
                 }
             } elseif (!$node instanceof \DOMComment) {
                 if (isset($config[$node->localName])) {
-                    if (!is_array($config[$node->localName])) {
+                    if (!is_array($config[$node->localName]) || !is_int(key($config[$node->localName]))) {
                         $config[$node->localName] = array($config[$node->localName]);
                     }
                     $config[$node->localName][] = static::convertDomElementToArray($node);

+ 4 - 0
tests/Symfony/Tests/Components/DependencyInjection/Loader/XmlFileLoaderTest.php

@@ -159,6 +159,10 @@ class XmlFileLoaderTest extends \PHPUnit_Framework_TestCase
         $doc = new \DOMDocument("1.0");
         $doc->loadXML('<foo><foo><!-- foo --></foo></foo>');
         $this->assertEquals(array('foo' => null), ProjectLoader2::convertDomElementToArray($doc->documentElement), '::convertDomElementToArray() converts a \DomElement to an array');
+
+        $doc = new \DOMDocument("1.0");
+        $doc->loadXML('<foo><foo foo="bar"/><foo foo="bar"/></foo>');
+        $this->assertEquals(array('foo' => array(array('foo' => 'bar'), array('foo' => 'bar'))), ProjectLoader2::convertDomElementToArray($doc->documentElement), '::convertDomElementToArray() converts a \DomElement to an array');
     }
 
     public function testExtensions()