[DI] Trigger exception when using '@id' name in parent option
This commit is contained in:
parent
8651758fc1
commit
1f67db626e
@ -378,6 +378,10 @@ class YamlFileLoader extends FileLoader
|
||||
}
|
||||
}
|
||||
|
||||
if ('' !== $service['parent'] && '@' === $service['parent'][0]) {
|
||||
throw new InvalidArgumentException(sprintf('The value of the "parent" option for the "%s" service must be the id of the service without the "@" prefix (replace "%s" with "%s").', $id, $service['parent'], substr($service['parent'], 1)));
|
||||
}
|
||||
|
||||
$definition = new ChildDefinition($service['parent']);
|
||||
} else {
|
||||
$definition = new Definition();
|
||||
|
@ -0,0 +1,6 @@
|
||||
services:
|
||||
foo:
|
||||
class: stdClass
|
||||
bar:
|
||||
class: stdClass
|
||||
parent: "@foo"
|
@ -511,6 +511,16 @@ class YamlFileLoaderTest extends TestCase
|
||||
$container->compile();
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
|
||||
* @expectedExceptionMessage The value of the "parent" option for the "bar" service must be the id of the service without the "@" prefix (replace "@foo" with "foo").
|
||||
*/
|
||||
public function testChildDefinitionWithWrongSyntaxThrowsException()
|
||||
{
|
||||
$loader = new YamlFileLoader(new ContainerBuilder(), new FileLocator(self::$fixturesPath.'/yaml'));
|
||||
$loader->load('bad_parent.yml');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
|
||||
* @expectedExceptionMessage The value of the "decorates" option for the "bar" service must be the id of the service without the "@" prefix (replace "@foo" with "foo").
|
||||
|
Reference in New Issue
Block a user