From 06d64d89e623ce661dacc1680f1616d4254e6f2e Mon Sep 17 00:00:00 2001 From: Wouter J Date: Sun, 10 Nov 2013 20:01:46 +0100 Subject: [PATCH] Do normalization on tag options --- .../Loader/XmlFileLoader.php | 4 ++++ .../Tests/Fixtures/xml/services10.xml | 16 +++++++++++++ .../Tests/Loader/XmlFileLoaderTest.php | 23 +++++++++++++++++++ .../DependencyInjection/services10.xml | 9 ++++++++ 4 files changed, 52 insertions(+) create mode 100644 src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services10.xml create mode 100644 src/Symfony/Component/DependencyInjection/services10.xml diff --git a/src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php b/src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php index f9a1c2a2eb0dc..9b2d46d28ef27 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php +++ b/src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php @@ -187,6 +187,10 @@ private function parseDefinition($id, $service, $file) continue; } + if (false !== strpos($name, '-') && false === strpos($name, '_') && !array_key_exists($normalizedName = str_replace('-', '_', $name), $parameters)) { + $parameters[$normalizedName] = SimpleXMLElement::phpize($value); + } + // keep not normalized key for BC too $parameters[$name] = SimpleXMLElement::phpize($value); } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services10.xml b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services10.xml new file mode 100644 index 0000000000000..a4da1bf74cf78 --- /dev/null +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services10.xml @@ -0,0 +1,16 @@ + + + + + + + + + diff --git a/src/Symfony/Component/DependencyInjection/Tests/Loader/XmlFileLoaderTest.php b/src/Symfony/Component/DependencyInjection/Tests/Loader/XmlFileLoaderTest.php index 6d36e2404c157..74db3c8eff5d4 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Loader/XmlFileLoaderTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Loader/XmlFileLoaderTest.php @@ -231,6 +231,29 @@ public function testLoadServices() $this->assertFalse($aliases['another_alias_for_foo']->isPublic()); } + public function testParsesTags() + { + $container = new ContainerBuilder(); + $loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml')); + $loader->load('services10.xml'); + + $services = $container->findTaggedServiceIds('foo_tag'); + $this->assertCount(1, $services); + + foreach ($services as $id => $tagAttributes) { + foreach ($tagAttributes as $attributes) { + $this->assertArrayHasKey('other_option', $attributes); + $this->assertEquals('lorem', $attributes['other_option']); + $this->assertArrayHasKey('other-option', $attributes, 'unnormalized tag attributes should not be removed'); + + $this->assertEquals('ciz', $attributes['some_option'], 'no overriding should be done when normalizing'); + $this->assertEquals('cat', $attributes['some-option']); + + $this->assertArrayNotHasKey('an_other_option', $attributes, 'normalization should not be done when an underscore is already found'); + } + } + } + public function testConvertDomElementToArray() { $doc = new \DOMDocument("1.0"); diff --git a/src/Symfony/Component/DependencyInjection/services10.xml b/src/Symfony/Component/DependencyInjection/services10.xml new file mode 100644 index 0000000000000..824d8b5d75396 --- /dev/null +++ b/src/Symfony/Component/DependencyInjection/services10.xml @@ -0,0 +1,9 @@ + + + + + + +