Skip to content

Commit 51a7b53

Browse files
Merge branch '2.7' into 2.8
* 2.7: [Twig] Fix deprecations with Twig 1.29 fix the docblock in regard to the role argument Cast result to int before adding to it
2 parents 55d7218 + 6dd4a0a commit 51a7b53

File tree

3 files changed

+30
-11
lines changed

3 files changed

+30
-11
lines changed

Loader/XmlFileLoader.php

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -369,21 +369,22 @@ private function getArgumentsAsPhp(\DOMElement $node, $name, $lowercase = true)
369369
$arg->setAttribute('key', $arg->getAttribute('name'));
370370
}
371371

372-
if (!$arg->hasAttribute('key')) {
373-
$key = !$arguments ? 0 : max(array_keys($arguments)) + 1;
374-
} else {
375-
$key = $arg->getAttribute('key');
376-
}
377-
378-
// parameter keys are case insensitive
379-
if ('parameter' == $name && $lowercase) {
380-
$key = strtolower($key);
381-
}
382-
383372
// this is used by DefinitionDecorator to overwrite a specific
384373
// argument of the parent definition
385374
if ($arg->hasAttribute('index')) {
386375
$key = 'index_'.$arg->getAttribute('index');
376+
} elseif (!$arg->hasAttribute('key')) {
377+
// Append an empty argument, then fetch its key to overwrite it later
378+
$arguments[] = null;
379+
$keys = array_keys($arguments);
380+
$key = array_pop($keys);
381+
} else {
382+
$key = $arg->getAttribute('key');
383+
384+
// parameter keys are case insensitive
385+
if ('parameter' == $name && $lowercase) {
386+
$key = strtolower($key);
387+
}
387388
}
388389

389390
switch ($arg->getAttribute('type')) {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
3+
<services>
4+
<service id="foo" class="Foo">
5+
<argument key="type">foo</argument>
6+
<argument>bar</argument>
7+
</service>
8+
</services>
9+
</container>

Tests/Loader/XmlFileLoaderTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,4 +577,13 @@ public function testAutowire()
577577

578578
$this->assertTrue($container->getDefinition('bar')->isAutowired());
579579
}
580+
581+
public function testArgumentWithKeyOutsideCollection()
582+
{
583+
$container = new ContainerBuilder();
584+
$loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml'));
585+
$loader->load('with_key_outside_collection.xml');
586+
587+
$this->assertSame(array('type' => 'foo', 'bar'), $container->getDefinition('foo')->getArguments());
588+
}
580589
}

0 commit comments

Comments
 (0)