[DI] fix detecting short service syntax in yaml

This commit is contained in:
Nicolas Grekas 2020-04-08 16:17:20 +02:00
parent f72dd9cafa
commit bf17165fb1
3 changed files with 18 additions and 1 deletions

View File

@ -299,7 +299,7 @@ class YamlFileLoader extends FileLoader
private function isUsingShortSyntax(array $service): bool
{
foreach ($service as $key => $value) {
if (\is_string($key) && ('' === $key || '$' !== $key[0])) {
if (\is_string($key) && ('' === $key || ('$' !== $key[0] && false === strpos($key, '\\')))) {
return false;
}
}

View File

@ -0,0 +1,6 @@
services:
foo_bar: [1, 2]
bar_foo:
$a: 'a'
App\Foo: 'foo'

View File

@ -205,6 +205,17 @@ class YamlFileLoaderTest extends TestCase
$this->assertEquals(['decorated', 'decorated.pif-pouf', 5, ContainerInterface::IGNORE_ON_INVALID_REFERENCE], $services['decorator_service_with_name_and_priority_and_on_invalid']->getDecoratedService());
}
public function testLoadShortSyntax()
{
$container = new ContainerBuilder();
$loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml'));
$loader->load('services_short_syntax.yml');
$services = $container->getDefinitions();
$this->assertSame([1, 2], $services['foo_bar']->getArguments());
$this->assertSame(['$a' => 'a', 'App\Foo' => 'foo'], $services['bar_foo']->getArguments());
}
public function testDeprecatedAliases()
{
$container = new ContainerBuilder();