Allow null values as tag attributes

This commit is contained in:
Lukas Kahwe Smith 2013-09-15 20:46:31 +02:00 committed by Fabien Potencier
parent 42f4b6db7b
commit 639b0fa967
3 changed files with 13 additions and 2 deletions

View File

@ -79,7 +79,7 @@ class CheckDefinitionValidityPass implements CompilerPassInterface
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));
}
}

View File

@ -224,7 +224,7 @@ class YamlFileLoader extends FileLoader
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));
}
}

View File

@ -61,6 +61,17 @@ class CheckDefinitionValidityPassTest extends \PHPUnit_Framework_TestCase
$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
*/