diff --git a/Dumper/XmlDumper.php b/Dumper/XmlDumper.php
index 05d424d15..6ae8d5c61 100644
--- a/Dumper/XmlDumper.php
+++ b/Dumper/XmlDumper.php
@@ -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 ?? '');
}
diff --git a/Tests/Fixtures/containers/container_non_scalar_tags.php b/Tests/Fixtures/containers/container_non_scalar_tags.php
index 76c69868c..2a1234fa7 100644
--- a/Tests/Fixtures/containers/container_non_scalar_tags.php
+++ b/Tests/Fixtures/containers/container_non_scalar_tags.php
@@ -10,6 +10,7 @@
$container
->register('foo', FooClass::class)
->addTag('foo_tag', [
+ 'name' => 'attributeName',
'foo' => 'bar',
'bar' => [
'foo' => 'bar',
diff --git a/Tests/Fixtures/xml/services_with_array_tags.xml b/Tests/Fixtures/xml/services_with_array_tags.xml
index 8e910be31..ba8d79057 100644
--- a/Tests/Fixtures/xml/services_with_array_tags.xml
+++ b/Tests/Fixtures/xml/services_with_array_tags.xml
@@ -4,6 +4,7 @@
+ attributeName
bar
bar
diff --git a/Tests/Fixtures/yaml/services_with_array_tags.yml b/Tests/Fixtures/yaml/services_with_array_tags.yml
index 3f580df3e..e4f355c04 100644
--- a/Tests/Fixtures/yaml/services_with_array_tags.yml
+++ b/Tests/Fixtures/yaml/services_with_array_tags.yml
@@ -7,4 +7,4 @@ services:
foo:
class: Bar\FooClass
tags:
- - foo_tag: { foo: bar, bar: { foo: bar, bar: foo } }
+ - foo_tag: { name: attributeName, foo: bar, bar: { foo: bar, bar: foo } }
diff --git a/Tests/Loader/XmlFileLoaderTest.php b/Tests/Loader/XmlFileLoaderTest.php
index c61fb0be5..d53fe9398 100644
--- a/Tests/Loader/XmlFileLoaderTest.php
+++ b/Tests/Loader/XmlFileLoaderTest.php
@@ -468,7 +468,7 @@ public function testParseServiceTagsWithArrayAttributes()
$loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml'));
$loader->load('services_with_array_tags.xml');
- $this->assertEquals(['foo_tag' => [['foo' => 'bar', 'bar' => ['foo' => 'bar', 'bar' => 'foo']]]], $container->getDefinition('foo')->getTags());
+ $this->assertEquals(['foo_tag' => [['name' => 'attributeName', 'foo' => 'bar', 'bar' => ['foo' => 'bar', 'bar' => 'foo']]]], $container->getDefinition('foo')->getTags());
}
public function testParseTagsWithoutNameThrowsException()