Skip to content

Commit

Permalink
Do normalization on tag options
Browse files Browse the repository at this point in the history
  • Loading branch information
wouterj authored and fabpot committed Dec 16, 2013
1 parent c05232f commit 06985eb
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 0 deletions.
Expand Up @@ -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);
}

Expand Down
@@ -0,0 +1,16 @@
<?xml version="1.0" ?>

<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service id="foo" class="BarClass">
<tag name="foo_tag"
some-option="cat"
some_option="ciz"
other-option="lorem"
an_other-option="ipsum"
/>
</service>
</services>
</container>
Expand Up @@ -198,6 +198,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");
Expand Down
9 changes: 9 additions & 0 deletions src/Symfony/Component/DependencyInjection/services10.xml
@@ -0,0 +1,9 @@
<?xml version="1.0" ?>

<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service id="foo" class="BarClass" />
</services>
</container>

0 comments on commit 06985eb

Please sign in to comment.