Skip to content

Commit

Permalink
[DependencyInjection] fix XmlDumper when a tag contains also a 'name'…
Browse files Browse the repository at this point in the history
… property
  • Loading branch information
lyrixx committed Mar 13, 2024
1 parent a0721fd commit 23dcbbb
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/Symfony/Component/DependencyInjection/Dumper/XmlDumper.php
Expand Up @@ -134,16 +134,17 @@ private function addService(Definition $definition, ?string $id, \DOMElement $pa
foreach ($tags as $name => $tags) {
foreach ($tags as $attributes) {
$tag = $this->document->createElement('tag');
if (!\array_key_exists('name', $attributes)) {
$tag->setAttribute('name', $name);
} else {
$tag->appendChild($this->document->createTextNode($name));
}

// Check if we have recursive attributes
if (array_filter($attributes, \is_array(...))) {
$tag->setAttribute('name', $name);
$this->addTagRecursiveAttributes($tag, $attributes);
} else {
if (!\array_key_exists('name', $attributes)) {
$tag->setAttribute('name', $name);
} else {
$tag->appendChild($this->document->createTextNode($name));
}
foreach ($attributes as $key => $value) {
$tag->setAttribute($key, $value ?? '');
}
Expand Down
Expand Up @@ -10,6 +10,7 @@
$container
->register('foo', FooClass::class)
->addTag('foo_tag', [
'name' => 'attributeName',
'foo' => 'bar',
'bar' => [
'foo' => 'bar',
Expand Down
Expand Up @@ -4,6 +4,7 @@
<service id="service_container" class="Symfony\Component\DependencyInjection\ContainerInterface" public="true" synthetic="true"/>
<service id="foo" class="Bar\FooClass">
<tag name="foo_tag">
<attribute name="name">attributeName</attribute>
<attribute name="foo">bar</attribute>
<attribute name="bar">
<attribute name="foo">bar</attribute>
Expand Down

0 comments on commit 23dcbbb

Please sign in to comment.