8000 bug #10629 [DependencyInjection] Fix #10626, use better check on attr… · symfony/symfony@bc6020d · GitHub
[go: up one dir, main page]

Skip to content

Commit bc6020d

Browse files
committed
bug #10629 [DependencyInjection] Fix #10626, use better check on attribute existence and values on XML load (romainneutron)
This PR was merged into the 2.5-dev branch. Discussion ---------- [DependencyInjection] Fix #10626, use better check on attribute existence and values on XML load | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #10626 | License | MIT Commits ------- 8163427 [DependencyInjection] Fix #10626, use better check on attribute existence and values on XML load
2 parents 8d69022 + 8163427 commit bc6020d

File tree

3 files changed

+35
-5
lines changed

3 files changed

+35
-5
lines changed

src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -307,12 +307,14 @@ private function getArgumentsAsPhp(\DOMElement $node, $name, $lowercase = true)
307307
{
308308
$arguments = array();
309309
foreach ($this->getChildren($node, $name) as $arg) {
310-
if ($nameAttr = $arg->getAttribute('name')) {
311-
$arg->setAttribute('key', $nameAttr);
310+
if ($arg->hasAttribute('name')) {
311+
$arg->setAttribute('key', $arg->getAttribute('name'));
312312
}
313313

314-
if (!$key = $arg->getAttribute('key')) {
314+
if (!$arg->hasAttribute('key')) {
315315
$key = !$arguments ? 0 : max(array_keys($arguments)) + 1;
316+
} else {
317+
$key = $arg->getAttribute('key');
316318
}
317319

318320
// parameter keys are case insensitive
@@ -322,8 +324,8 @@ private function getArgumentsAsPhp(\DOMElement $node, $name, $lowercase = true)
322324

323325
// this is used by DefinitionDecorator to overwrite a specific
324326
// argument of the parent definition
325-
if ($index = $arg->getAttribute('index')) {
326-
$key = 'index_'.$index;
327+
if ($arg->hasAttribute('index')) {
328+
$key = 'index_'.$arg->getAttribute('index');
327329
}
328330

329331
switch ($arg->getAttribute('type')) {
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<container xmlns="http://symfony.com/schema/dic/services"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
5+
<services>
6+
<service id="monolog.logger" parent="monolog.logger_prototype" public="false">
7+
<argument index="0">app</argument>
8+
</service>
9+
10+
<service id="logger" alias="monolog.logger" />
11+
12+
<service id="monolog.logger" parent="monolog.logger_prototype" public="false">
13+
<argument index="0">app</argument>
14+
</service>
15+
<service id="monolog.logger_prototype" class="Symfony\Bridge\Monolog\Logger" abstract="true">
16+
<argument /><!-- Channel -->
17+
</service>
18+
</services>
19+
</container>

src/Symfony/Component/DependencyInjection/Tests/Loader/XmlFileLoaderTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,4 +444,13 @@ public function testXmlNamespaces()
444444
$this->assertEquals(1, count($services['foo']->getTag('foo.tag')), '->load parses <srv:tag> elements');
445445
$this->assertEquals(array(array('setBar', array('foo'))), $services['foo']->getMethodCalls(), '->load() parses the <srv:call> tag');
446446
}
447+
448+
public function testLoadIndexedArguments()
449+
{
450+
$container = new ContainerBuilder();
451+
$loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml'));
452+
$loader->load('services14.xml');
453+
454+
$this->assertEquals(array('index_0' => 'app'), $container->findDefinition('logger')->getArguments());
455+
}
447456
}

0 commit comments

Comments
 (0)
0