diff --git a/src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php b/src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php index 58c8301065..f688cfab73 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php +++ b/src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php @@ -307,12 +307,14 @@ class XmlFileLoader extends FileLoader { $arguments = array(); foreach ($this->getChildren($node, $name) as $arg) { - if ($nameAttr = $arg->getAttribute('name')) { - $arg->setAttribute('key', $nameAttr); + if ($arg->hasAttribute('name')) { + $arg->setAttribute('key', $arg->getAttribute('name')); } - if (!$key = $arg->getAttribute('key')) { + if (!$arg->hasAttribute('key')) { $key = !$arguments ? 0 : max(array_keys($arguments)) + 1; + } else { + $key = $arg->getAttribute('key'); } // parameter keys are case insensitive @@ -322,8 +324,8 @@ class XmlFileLoader extends FileLoader // this is used by DefinitionDecorator to overwrite a specific // argument of the parent definition - if ($index = $arg->getAttribute('index')) { - $key = 'index_'.$index; + if ($arg->hasAttribute('index')) { + $key = 'index_'.$arg->getAttribute('index'); } switch ($arg->getAttribute('type')) { diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services14.xml b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services14.xml new file mode 100644 index 0000000000..73446214e4 --- /dev/null +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services14.xml @@ -0,0 +1,19 @@ + + + + + app + + + + + + app + + + + + + diff --git a/src/Symfony/Component/DependencyInjection/Tests/Loader/XmlFileLoaderTest.php b/src/Symfony/Component/DependencyInjection/Tests/Loader/XmlFileLoaderTest.php index 1721bc3d9c..c9ad753c9b 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Loader/XmlFileLoaderTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Loader/XmlFileLoaderTest.php @@ -444,4 +444,13 @@ class XmlFileLoaderTest extends \PHPUnit_Framework_TestCase $this->assertEquals(1, count($services['foo']->getTag('foo.tag')), '->load parses elements'); $this->assertEquals(array(array('setBar', array('foo'))), $services['foo']->getMethodCalls(), '->load() parses the tag'); } + + public function testLoadIndexedArguments() + { + $container = new ContainerBuilder(); + $loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml')); + $loader->load('services14.xml'); + + $this->assertEquals(array('index_0' => 'app'), $container->findDefinition('logger')->getArguments()); + } }