Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0d38842

Browse files
committed
[DependencyInjection] fix XmlDumper when a tag contains also a 'name' property
1 parent a0721fd commit 0d38842

File tree

5 files changed

+10
-7
lines changed

5 files changed

+10
-7
lines changed

src/Symfony/Component/DependencyInjection/Dumper/XmlDumper.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,16 +134,17 @@ private function addService(Definition $definition, ?string $id, \DOMElement $pa
134134
foreach ($tags as $name => $tags) {
135135
foreach ($tags as $attributes) {
136136
$tag = $this->document->createElement('tag');
137-
if (!\array_key_exists('name', $attributes)) {
138-
$tag->setAttribute('name', $name);
139-
} else {
140-
$tag->appendChild($this->document->createTextNode($name));
141-
}
142137

143138
// Check if we have recursive attributes
144139
if (array_filter($attributes, \is_array(...))) {
140+
$tag->setAttribute('name', $name);
145141
$this->addTagRecursiveAttributes($tag, $attributes);
146142
} else {
143+
if (!\array_key_exists('name', $attributes)) {
144+
$tag->setAttribute('name', $name);
145+
} else {
146+
$tag->appendChild($this->document->createTextNode($name));
147+
}
147148
foreach ($attributes as $key => $value) {
148149
$tag->setAttribute($key, $value ?? '');
149150
}

src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container_non_scalar_tags.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
$container
1111
->register('foo', FooClass::class)
1212
->addTag('foo_tag', [
13+
'name' => 'attributeName',
1314
'foo' => 'bar',
1415
'bar' => [
1516
'foo' => 'bar',

src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services_with_array_tags.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<service id="service_container" class="Symfony\Component\DependencyInjection\ContainerInterface" public="true" synthetic="true"/>
55
<service id="foo" class="Bar\FooClass">
66
<tag name="foo_tag">
7+
<attribute name="name">attributeName</attribute>
78
<attribute name="foo">bar</attribute>
89
<attribute name="bar">
910
<attribute name="foo">bar</attribute>

src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services_with_array_tags.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ services:
77
foo:
88
class: Bar\FooClass
99
tags:
10-
- foo_tag: { foo: bar, bar: { foo: bar, bar: foo } }
10+
- foo_tag: { name: attributeName, foo: bar, bar: { foo: bar, bar: foo } }

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ public function testParseServiceTagsWithArrayAttributes()
460460
$loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml'));
461461
$loader->load('services_with_array_tags.xml');
462462

463-
$this->assertEquals(['foo_tag' => [['foo' => 'bar', 'bar' => ['foo' => 'bar', 'bar' => 'foo']]]], $container->getDefinition('foo')->getTags());
463+
$this->assertEquals(['foo_tag' => [['name' => 'attributeName', 'foo' => 'bar', 'bar' => ['foo' => 'bar', 'bar' => 'foo']]]], $container->getDefinition('foo')->getTags());
464464
}
465465

466466
public function testParseTagsWithoutNameThrowsException()

0 commit comments

Comments
 (0)