diff --git a/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php b/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php index 8036933ad5..f57ba587c8 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php +++ b/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php @@ -288,6 +288,10 @@ class YamlFileLoader extends FileLoader } if (isset($service['decorates'])) { + if ('' !== $service['decorates'] && '@' === $service['decorates'][0]) { + 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))); + } + $renameId = isset($service['decoration_inner_name']) ? $service['decoration_inner_name'] : null; $definition->setDecoratedService($service['decorates'], $renameId); } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/bad_decorates.yml b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/bad_decorates.yml new file mode 100644 index 0000000000..79c048a847 --- /dev/null +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/bad_decorates.yml @@ -0,0 +1,7 @@ +services: + foo: + class: stdClass + bar: + class: stdClass + decorates: "@foo" + arguments: ["@bar.inner"] diff --git a/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php b/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php index bc3ca77622..78f9bafc15 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php @@ -297,4 +297,14 @@ class YamlFileLoaderTest extends \PHPUnit_Framework_TestCase $loader = new YamlFileLoader(new ContainerBuilder(), new FileLocator(self::$fixturesPath.'/yaml')); $loader->load('tag_name_no_string.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"). + */ + public function testDecoratedServicesWithWrongSyntaxThrowsException() + { + $loader = new YamlFileLoader(new ContainerBuilder(), new FileLocator(self::$fixturesPath.'/yaml')); + $loader->load('bad_decorates.yml'); + } }