Skip to content

Commit

Permalink
Allow null values as tag attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
lsmith77 authored and fabpot committed Sep 16, 2013
1 parent 42f4b6d commit 639b0fa
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
Expand Up @@ -79,7 +79,7 @@ public function process(ContainerBuilder $container)
foreach ($definition->getTags() as $name => $tags) {
foreach ($tags as $attributes) {
foreach ($attributes as $attribute => $value) {
if (!is_scalar($value)) {
if (!is_scalar($value) && null !== $value) {
throw new RuntimeException(sprintf('A "tags" attribute must be of a scalar-type for service "%s", tag "%s", attribute "%s".', $id, $name, $attribute));
}
}
Expand Down
Expand Up @@ -224,7 +224,7 @@ private function parseDefinition($id, $service, $file)
unset($tag['name']);

foreach ($tag as $attribute => $value) {
if (!is_scalar($value)) {
if (!is_scalar($value) && null !== $value) {
throw new InvalidArgumentException(sprintf('A "tags" attribute must be of a scalar-type for service "%s", tag "%s", attribute "%s" in %s.', $id, $name, $attribute, $file));
}
}
Expand Down
Expand Up @@ -61,6 +61,17 @@ public function testProcess()
$this->process($container);
}

public function testValidTags()
{
$container = new ContainerBuilder();
$container->register('a', 'class')->addTag('foo', array('bar' => 'baz'));
$container->register('b', 'class')->addTag('foo', array('bar' => null));
$container->register('c', 'class')->addTag('foo', array('bar' => 1));
$container->register('d', 'class')->addTag('foo', array('bar' => 1.1));

$this->process($container);
}

/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
*/
Expand Down

0 comments on commit 639b0fa

Please sign in to comment.