[DI] fix detecting short service syntax in yaml
This commit is contained in:
parent
f72dd9cafa
commit
bf17165fb1
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,6 @@
|
||||
services:
|
||||
foo_bar: [1, 2]
|
||||
|
||||
bar_foo:
|
||||
$a: 'a'
|
||||
App\Foo: 'foo'
|
@ -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();
|
||||
|
Reference in New Issue
Block a user