8000 [DI] Trigger exception when using '@id' name in parent option · symfony/symfony@1f67db6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1f67db6

Browse files
Seb33300fabpot
authored andcommitted
[DI] Trigger exception when using '@id' name in parent option
1 parent 8651758 commit 1f67db6

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,10 @@ private function parseDefinition($id, $service, $file, array $defaults)
378378
}
379379
}
380380

381+
if ('' !== $service['parent'] && '@' === $service['parent'][0]) {
382+
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)));
383+
}
384+
381385
$definition = new ChildDefinition($service['parent']);
382386
} else {
383387
$definition = new Definition();
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
services:
2+
foo:
3+
class: stdClass
4+
bar:
5+
class: stdClass
6+
parent: "@foo"

src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,16 @@ public function testDefaultsAndChildDefinitionNotAllowed()
511511
$container->compile();
512512
}
513513

514+
/**
515+
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
516+
* @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").
517+
*/
518+
public function testChildDefinitionWithWrongSyntaxThrowsException()
519+
{
520+
$loader = new YamlFileLoader(new ContainerBuilder(), new FileLocator(self::$fixturesPath.'/yaml'));
521+
$loader->load('bad_parent.yml');
522+
}
523+
514524
/**
515525
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
516526
* @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").

0 commit comments

Comments
 (0)
0