8000 Allow null values as tag attributes · symfony/symfony@639b0fa · GitHub
[go: up one dir, main page]

Skip to content

Commit 639b0fa

Browse files
lsmith77fabpot
authored andcommitted
Allow null values as tag attributes
1 parent 42f4b6d commit 639b0fa

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

src/Symfony/Component/DependencyInjection/Compiler/CheckDefinitionValidityPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function process(ContainerBuilder $container)
7979
foreach ($definition->getTags() as $name => $tags) {
8080
foreach ($tags as $attributes) {
8181
foreach ($attributes as $attribute => $value) {
82-
if (!is_scalar($value)) {
82+
if (!is_scalar($value) && null !== $value) {
8383
throw new RuntimeException(sprintf('A "tags" attribute must be of a scalar-type for service "%s", tag "%s", attribute "%s".', $id, $name, $attribute));
8484
}
8585
}

src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ private function parseDefinition($id, $service, $file)
224224
unset($tag['name']);
225225

226226
foreach ($tag as $attribute => $value) {
227-
if (!is_scalar($value)) {
227+
if (!is_scalar($value) && null !== $value) {
228228
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));
229229
}
230230
}

src/Symfony/Component/DependencyInjection/Tests/Compiler/CheckDefinitionValidityPassTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,17 @@ public function testProcess()
6161
$this->process($container);
6262
}
6363

64+
public function testValidTags()
65+
{
66+
$container = new ContainerBuilder();
67+
$container->register('a', 'class')->addTag('foo', array('bar' => 'baz'));
68+
$container->register('b', 'class')->addTag('foo', array('bar' => null));
69+
$container->register('c', 'class')->addTag('foo', array('bar' => 1));
70+
$container->register('d', 'class')->addTag('foo', array('bar' => 1.1));
71+
72+
$this->process($container);
73+
}
74+
6475
/**
6576
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
6677
*/

0 commit comments

Comments
 (0)
0