Skip to content

Commit e7690ba

Browse files
javiereguiluzfabpot
authored andcommitted
Improved the error message when using "@" in a decorated service
1 parent 3af65d7 commit e7690ba

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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy