Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a36b981

Browse filesBrowse files
committed
feature #59257 [DependencyInjection] Support @> as a shorthand for !service_closure in YamlFileLoader (chx)
This PR was merged into the 7.3 branch. Discussion ---------- [DependencyInjection] Support `@>` as a shorthand for `!service_closure` in YamlFileLoader | Q | A | ------------- | --- | Branch? | 7.3 | Bug fix? | no | New feature? | yes | Deprecations? | no | Issues | Fix #59255 | License | MIT Commits ------- ba29960 [DependencyInjection] Support @> as a shorthand for !service_closure in YamlFileLoader (Issue #59255)
2 parents 8ce6d45 + ba29960 commit a36b981
Copy full SHA for a36b981

File tree

4 files changed

+23
-0
lines changed
Filter options

4 files changed

+23
-0
lines changed

‎src/Symfony/Component/DependencyInjection/CHANGELOG.md

Copy file name to clipboardExpand all lines: 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

Copy file name to clipboardExpand all lines: 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

Copy file name to clipboardExpand all lines: 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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.