Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 68a910f

Browse files
committed
feature #28315 [DI] Trigger exception when using '@id' name in parent option (Seb33300)
This PR was squashed before being merged into the 4.2-dev branch (closes #28315). Discussion ---------- [DI] Trigger exception when using '@id' name in parent option Same exception [already triggered](https://github.com/symfony/symfony/blob/master/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php#L505) on the `decorates` option. | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | Note sure if I should submit this change for master or previous branches... Commits ------- 1f67db6 [DI] Trigger exception when using '@id' name in parent option
2 parents cabbf51 + 1f67db6 commit 68a910f

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)