From 70c42f2676eb82ba2d6137919ddf50b41eaa73ee Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Wed, 16 Nov 2016 18:59:59 +0100 Subject: [PATCH] Cast result to int before adding to it This fixes the occasional warning about non-numeric values when using PHP 7.1 --- .../Loader/XmlFileLoader.php | 23 ++++++++++--------- .../xml/with_key_outside_collection.xml | 9 ++++++++ .../Tests/Loader/XmlFileLoaderTest.php | 9 ++++++++ 3 files changed, 30 insertions(+), 11 deletions(-) create mode 100644 src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/with_key_outside_collection.xml diff --git a/src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php b/src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php index e60c2f7df76c1..b3e4ef4d3e7c1 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php +++ b/src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php @@ -346,21 +346,22 @@ private function getArgumentsAsPhp(\DOMElement $node, $name, $lowercase = true) $arg->setAttribute('key', $arg->getAttribute('name')); } - if (!$arg->hasAttribute('key')) { - $key = !$arguments ? 0 : max(array_keys($arguments)) + 1; - } else { - $key = $arg->getAttribute('key'); - } - - // parameter keys are case insensitive - if ('parameter' == $name && $lowercase) { - $key = strtolower($key); - } - // this is used by DefinitionDecorator to overwrite a specific // argument of the parent definition if ($arg->hasAttribute('index')) { $key = 'index_'.$arg->getAttribute('index'); + } elseif (!$arg->hasAttribute('key')) { + // Append an empty argument, then fetch its key to overwrite it later + $arguments[] = null; + $keys = array_keys($arguments); + $key = array_pop($keys); + } else { + $key = $arg->getAttribute('key'); + + // parameter keys are case insensitive + if ('parameter' == $name && $lowercase) { + $key = strtolower($key); + } } switch ($arg->getAttribute('type')) { diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/with_key_outside_collection.xml b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/with_key_outside_collection.xml new file mode 100644 index 0000000000000..5f3a2843612df --- /dev/null +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/with_key_outside_collection.xml @@ -0,0 +1,9 @@ + + + + + foo + bar + + + diff --git a/src/Symfony/Component/DependencyInjection/Tests/Loader/XmlFileLoaderTest.php b/src/Symfony/Component/DependencyInjection/Tests/Loader/XmlFileLoaderTest.php index 2de5915f4ef41..fd4517228430c 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Loader/XmlFileLoaderTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Loader/XmlFileLoaderTest.php @@ -542,4 +542,13 @@ public function testLoadInlinedServices() $this->assertSame('Baz', $barConfigurator[0]->getClass()); $this->assertSame('configureBar', $barConfigurator[1]); } + + public function testArgumentWithKeyOutsideCollection() + { + $container = new ContainerBuilder(); + $loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml')); + $loader->load('with_key_outside_collection.xml'); + + $this->assertSame(array('type' => 'foo', 'bar'), $container->getDefinition('foo')->getArguments()); + } } pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy