Skip to content

Commit 2b91cff

Browse files
[DI] fix detecting short service syntax in yaml
1 parent 755b188 commit 2b91cff

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

Loader/YamlFileLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ private function parseDefaults(array &$content, string $file): array
299299
private function isUsingShortSyntax(array $service): bool
300300
{
301301
foreach ($service as $key => $value) {
302-
if (\is_string($key) && ('' === $key || '$' !== $key[0])) {
302+
if (\is_string($key) && ('' === $key || ('$' !== $key[0] && false === strpos($key, '\\')))) {
303303
return false;
304304
}
305305
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
services:
2+
foo_bar: [1, 2]
3+
4+
bar_foo:
5+
$a: 'a'
6+
App\Foo: 'foo'

Tests/Loader/YamlFileLoaderTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,17 @@ public function testLoadServices()
205205
$this->assertEquals(['decorated', 'decorated.pif-pouf', 5, ContainerInterface::IGNORE_ON_INVALID_REFERENCE], $services['decorator_service_with_name_and_priority_and_on_invalid']->getDecoratedService());
206206
}
207207

208+
public function testLoadShortSyntax()
209+
{
210+
$container = new ContainerBuilder();
211+
$loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml'));
212+
$loader->load('services_short_syntax.yml');
213+
$services = $container->getDefinitions();
214+
215+
$this->assertSame([1, 2], $services['foo_bar']->getArguments());
216+
$this->assertSame(['$a' => 'a', 'App\Foo' => 'foo'], $services['bar_foo']->getArguments());
217+
}
218+
208219
public function testDeprecatedAliases()
209220
{
210221
$container = new ContainerBuilder();

0 commit comments

Comments
 (0)