From e63ff6e04b37ca75f2823cef1e455957552dd002 Mon Sep 17 00:00:00 2001 From: Kris Wallsmith Date: Thu, 17 Jun 2010 06:40:44 -0700 Subject: [PATCH] [DependencyInjection] fixed conversion of DOM to array when DOM includes multiple elements with the same name --- .../Components/DependencyInjection/Loader/XmlFileLoader.php | 2 +- .../DependencyInjection/Loader/XmlFileLoaderTest.php | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Components/DependencyInjection/Loader/XmlFileLoader.php b/src/Symfony/Components/DependencyInjection/Loader/XmlFileLoader.php index 3ed4c9342db4..0ac24b26d479 100644 --- a/src/Symfony/Components/DependencyInjection/Loader/XmlFileLoader.php +++ b/src/Symfony/Components/DependencyInjection/Loader/XmlFileLoader.php @@ -374,7 +374,7 @@ static public function convertDomElementToArray(\DomElement $element) } } 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); diff --git a/tests/Symfony/Tests/Components/DependencyInjection/Loader/XmlFileLoaderTest.php b/tests/Symfony/Tests/Components/DependencyInjection/Loader/XmlFileLoaderTest.php index 679e480aca8e..40b08229a767 100644 --- a/tests/Symfony/Tests/Components/DependencyInjection/Loader/XmlFileLoaderTest.php +++ b/tests/Symfony/Tests/Components/DependencyInjection/Loader/XmlFileLoaderTest.php @@ -159,6 +159,10 @@ public function testConvertDomElementToArray() $doc = new \DOMDocument("1.0"); $doc->loadXML(''); $this->assertEquals(array('foo' => null), ProjectLoader2::convertDomElementToArray($doc->documentElement), '::convertDomElementToArray() converts a \DomElement to an array'); + + $doc = new \DOMDocument("1.0"); + $doc->loadXML(''); + $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()