10000 [DependencyInjection] Support @> as a shorthand for !service_closure … · symfony/symfony@ba29960 · GitHub
[go: up one dir, main page]

Skip to content

Commit ba29960

Browse files
chxnicolas-grekas
authored andcommitted
[DependencyInjection] Support @> as a shorthand for !service_closure in YamlFileLoader (Issue #59255)
1 parent 8ce6d45 commit ba29960

File tree

4 files changed

+23
-0
lines changed

4 files changed

+23
-0
lines changed

src/Symfony/Component/DependencyInjection/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CHANGELOG
55
---
66

77
* Make `#[AsTaggedItem]` repeatable
8+
* Support `@>` as a shorthand for `!service_closure` in yaml files
89

910
7.2
1011
---

src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php

+5
Original file line numberDiff line numberDiff line change
@@ -923,6 +923,11 @@ private function resolveServices(mixed $value, string $file, bool $isParameter =
923923

924924
return new Expression(substr($value, 2));
925925
} elseif (\is_string($value) && str_starts_with($value, '@')) {
926+
if (str_starts_with($value, '@>')) {
927+
$argument = $this->resolveServices(substr_replace($value, '', 1, 1), $file, $isParameter);
928+
929+
return new ServiceClosureArgument($argument);
930+
}
926931
if (str_starts_with($value, '@@')) {
927932
$value = substr($value, 1);
928933
$invalidBehavior = null;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
services:
2+
service_container:
3+
class: Symfony\Component\DependencyInjection\ContainerInterface
4+
public: true
5+
synthetic: true
6+
foo:
7+
class: Foo
8+
arguments: ['@>bar']

src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php

+9
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,15 @@ public function testParseServiceClosure()
466466
$this->assertEquals(new ServiceClosureArgument(new Reference('bar', ContainerInterface::IGNORE_ON_INVALID_REFERENCE)), $container->getDefinition('foo')->getArgument(0));
467467
}
468468

469+
public function testParseShortServiceClosure()
470+
{
471+
$container = new ContainerBuilder();
472+
$loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml'));
473+
$loader->load('services_with_short_service_closure.yml');
474+
475+
$this->assertEquals(new ServiceClosureArgument(new Reference('bar')), $container->getDefinition('foo')->getArgument(0));
476+
}
477+
469478
public function testNameOnlyTagsAreAllowedAsString()
470479
{
471480
$container = new ContainerBuilder();

0 commit comments

Comments
 (0)
0