diff --git a/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php b/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php index a31959e45655..986ccf0b81f9 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php +++ b/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php @@ -299,7 +299,7 @@ private function parseDefaults(array &$content, string $file): array 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; } } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services_short_syntax.yml b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services_short_syntax.yml new file mode 100644 index 000000000000..16ddb6bdf241 --- /dev/null +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services_short_syntax.yml @@ -0,0 +1,6 @@ +services: + foo_bar: [1, 2] + + bar_foo: + $a: 'a' + App\Foo: 'foo' diff --git a/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php b/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php index f40fc22cc345..eb6d01a19749 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php @@ -205,6 +205,17 @@ public function testLoadServices() $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();