Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DI] fix detecting short service syntax in yaml #36387

Merged
merged 1 commit into from Apr 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -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;
}
}
Expand Down
@@ -0,0 +1,6 @@
services:
foo_bar: [1, 2]

bar_foo:
$a: 'a'
App\Foo: 'foo'
Expand Up @@ -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();
Expand Down