10000 bug #17687 Improved the error message when using "@" in a decorated s… · symfony/symfony@aab2783 · GitHub
[go: up one dir, main page]

Skip to content

Commit aab2783

Browse files
committed
bug #17687 Improved the error message when using "@" in a decorated service (javiereguiluz)
This PR was squashed before being merged into the 2.7 branch (closes #17687). Discussion ---------- Improved the error message when using "@" in a decorated service | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #17666 | License | MIT | Doc PR | - Commits ------- e7690ba Improved the error message when using "@" in a decorated service
2 parents 9d58ad9 + e7690ba commit aab2783

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,10 @@ private function parseDefinition($id, $service, $file)
288288
}
289289

290290
if (isset($service['decorates'])) {
291+
if ('' !== $service['decorates'] && '@' === $service['decorates'][0]) {
292+
throw new InvalidArgumentException(sprintf('The value of the "decorates" option for the "%s" service must be the id of the service without the "@" prefix (replace "%s" with "%s").', $id, $service['decorates'], substr($service['decorates'], 1)));
293+
}
294+
291295
$renameId = isset($service['decoration_inner_name']) ? $service['decoration_inner_name'] : null;
292296
$definition->setDecoratedService($service['decorates'], $renameId);
293297
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
services:
2+
foo:
3+
class: stdClass
4+
bar:
5+
class: stdClass
6+
decorates: "@foo"
7+
arguments: ["@bar.inner"]

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,4 +297,14 @@ public function testTagWithNonStringNameThrowsException()
297297
$loader = new YamlFileLoader(new ContainerBuilder(), new FileLocator(self::$fixturesPath.'/yaml'));
298298
$loader->load('tag_name_no_string.yml');
299299
}
300+
301+
/**
302+
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
303+
* @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").
304+
*/
305+
public function testDecoratedServicesWithWrongSyntaxThrowsException()
306+
{
307+
$loader = new YamlFileLoader(new ContainerBuilder(), new FileLocator(self::$fixturesPath.'/yaml'));
308+
$loader->load('bad_decorates.yml');
309+
}
300310
}

0 commit comments

Comments
 (0)
0