Improved the error message when using "@" in a decorated service
This commit is contained in:
parent
3af65d72ec
commit
e7690ba5c4
@ -288,6 +288,10 @@ class YamlFileLoader extends FileLoader
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isset($service['decorates'])) {
|
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;
|
$renameId = isset($service['decoration_inner_name']) ? $service['decoration_inner_name'] : null;
|
||||||
$definition->setDecoratedService($service['decorates'], $renameId);
|
$definition->setDecoratedService($service['decorates'], $renameId);
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,7 @@
|
|||||||
|
services:
|
||||||
|
foo:
|
||||||
|
class: stdClass
|
||||||
|
bar:
|
||||||
|
class: stdClass
|
||||||
|
decorates: "@foo"
|
||||||
|
arguments: ["@bar.inner"]
|
@ -297,4 +297,14 @@ class YamlFileLoaderTest extends \PHPUnit_Framework_TestCase
|
|||||||
$loader = new YamlFileLoader(new ContainerBuilder(), new FileLocator(self::$fixturesPath.'/yaml'));
|
$loader = new YamlFileLoader(new ContainerBuilder(), new FileLocator(self::$fixturesPath.'/yaml'));
|
||||||
$loader->load('tag_name_no_string.yml');
|
$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');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user