Skip to content

[DependencyInjection] Support @> as a shorthand for !service_closure in YamlFileLoader #59257

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

Merged
merged 1 commit into from
Jan 6, 2025
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Symfony/Component/DependencyInjection/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ CHANGELOG
---

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

7.2
---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -923,6 +923,11 @@ private function resolveServices(mixed $value, string $file, bool $isParameter =

return new Expression(substr($value, 2));
} elseif (\is_string($value) && str_starts_with($value, '@')) {
if (str_starts_with($value, '@>')) {
$argument = $this->resolveServices(substr_replace($value, '', 1, 1), $file, $isParameter);

return new ServiceClosureArgument($argument);
}
if (str_starts_with($value, '@@')) {
$value = substr($value, 1);
$invalidBehavior = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
services:
service_container:
class: Symfony\Component\DependencyInjection\ContainerInterface
public: true
synthetic: true
foo:
class: Foo
arguments: ['@>bar']
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,15 @@ public function testParseServiceClosure()
$this->assertEquals(new ServiceClosureArgument(new Reference('bar', ContainerInterface::IGNORE_ON_INVALID_REFERENCE)), $container->getDefinition('foo')->getArgument(0));
}

public function testParseShortServiceClosure()
{
$container = new ContainerBuilder();
$loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml'));
$loader->load('services_with_short_service_closure.yml');

$this->assertEquals(new ServiceClosureArgument(new Reference('bar')), $container->getDefinition('foo')->getArgument(0));
}

public function testNameOnlyTagsAreAllowedAsString()
{
$container = new ContainerBuilder();
Expand Down