Allow null values as tag attributes
This commit is contained in:
parent
42f4b6db7b
commit
639b0fa967
@ -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));
|
||||
}
|
||||
}
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
*/
|
||||
|
Reference in New Issue
Block a user