[DependencyInjection] Yaml: check if is an array before using it
This commit is contained in:
parent
4491eb6463
commit
1c9b5c9916
@ -332,6 +332,9 @@ class YamlFileLoader extends FileLoader
|
||||
}
|
||||
|
||||
$tags = isset($service['tags']) ? $service['tags'] : array();
|
||||
if (!is_array($tags)) {
|
||||
throw new InvalidArgumentException(sprintf('Parameter "tags" must be an array for service "%s" in %s. Check your YAML syntax.', $id, $file));
|
||||
}
|
||||
|
||||
if (!isset($defaults['tags'])) {
|
||||
// no-op
|
||||
@ -343,11 +346,6 @@ class YamlFileLoader extends FileLoader
|
||||
$tags = array_merge($tags, $defaults['tags']);
|
||||
}
|
||||
|
||||
if (null !== $tags) {
|
||||
if (!is_array($tags)) {
|
||||
throw new InvalidArgumentException(sprintf('Parameter "tags" must be an array for service "%s" in %s. Check your YAML syntax.', $id, $file));
|
||||
}
|
||||
|
||||
foreach ($tags as $tag) {
|
||||
if (!is_array($tag)) {
|
||||
$tag = array('name' => $tag);
|
||||
@ -371,7 +369,6 @@ class YamlFileLoader extends FileLoader
|
||||
|
||||
$definition->addTag($name, $tag);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($service['decorates'])) {
|
||||
if ('' !== $service['decorates'] && '@' === $service['decorates'][0]) {
|
||||
|
@ -0,0 +1,7 @@
|
||||
services:
|
||||
_defaults:
|
||||
tags: ['foo']
|
||||
|
||||
Foo\Bar:
|
||||
tags: invalid
|
||||
inherit_tags: true
|
@ -1,5 +1,4 @@
|
||||
services:
|
||||
|
||||
foo_bar:
|
||||
class: FooBarClass
|
||||
configurator: foo_bar_configurator:configure
|
||||
|
@ -408,4 +408,14 @@ class YamlFileLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
$loader = new YamlFileLoader(new ContainerBuilder(), new FileLocator(self::$fixturesPath.'/yaml'));
|
||||
$loader->load('bad_decorates.yml');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
|
||||
* @expectedExceptionMessage Parameter "tags" must be an array for service "Foo\Bar" in services31_invalid_tags.yml. Check your YAML syntax.
|
||||
*/
|
||||
public function testInvalidTagsWithDefaults()
|
||||
{
|
||||
$loader = new YamlFileLoader(new ContainerBuilder(), new FileLocator(self::$fixturesPath.'/yaml'));
|
||||
$loader->load('services31_invalid_tags.yml');
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user