Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

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

Sign up
Appearance settings

Commit92ef476

Browse files
feature#33623 [DependencyInjection] Allow binding iterable and tagged services (lyrixx)
This PR was merged into the 4.4 branch.Discussion----------[DependencyInjection] Allow binding iterable and tagged services| Q | A| ------------- | ---| Branch? | 4.4| Bug fix? | no| New feature? | yes| Deprecations? | no| Tickets || License | MIT| Doc PR |This will allow:```yamlservices: _defaults: bind: iterable $rules: !tagged_iterator app.foo.rule _instanceof: App\Foo\Rule\RuleInterface: tags: ['app.foo.rule']```Commits-------2055a55 [DependencyInjection] Allow binding iterable and tagged services
2 parents1efae63 +2055a55 commit92ef476

File tree

4 files changed

+11
-5
lines changed

4 files changed

+11
-5
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ CHANGELOG
99
* deprecated support for short factories and short configurators in Yaml
1010
* deprecated`tagged` in favor of`tagged_iterator`
1111
* deprecated passing an instance of`Symfony\Component\DependencyInjection\Parameter` as class name to`Symfony\Component\DependencyInjection\Definition`
12+
* added support for binding iterable and tagged services
1213

1314
4.3.0
1415
-----

‎src/Symfony/Component/DependencyInjection/Compiler/ResolveBindingsPass.php‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespaceSymfony\Component\DependencyInjection\Compiler;
1313

1414
useSymfony\Component\DependencyInjection\Argument\BoundArgument;
15+
useSymfony\Component\DependencyInjection\Argument\TaggedIteratorArgument;
1516
useSymfony\Component\DependencyInjection\ContainerBuilder;
1617
useSymfony\Component\DependencyInjection\Definition;
1718
useSymfony\Component\DependencyInjection\Exception\InvalidArgumentException;
@@ -120,8 +121,8 @@ protected function processValue($value, $isRoot = false)
120121
continue;
121122
}
122123

123-
if (null !==$bindingValue && !$bindingValueinstanceof Reference && !$bindingValueinstanceof Definition) {
124-
thrownewInvalidArgumentException(sprintf('Invalid value for binding key "%s" for service "%s": expected null, an instance of %s or an instance of %s, %s given.',$key,$this->currentId, Reference::class, Definition::class,\gettype($bindingValue)));
124+
if (null !==$bindingValue && !$bindingValueinstanceof Reference && !$bindingValueinstanceof Definition && !$bindingValueinstanceof TaggedIteratorArgument) {
125+
thrownewInvalidArgumentException(sprintf('Invalid value for binding key "%s" for service "%s": expected null, an instance of %s or an instance of %s or an instance of %s, %s given.',$key,$this->currentId, Reference::class, Definition::class, TaggedIteratorArgument::class,\gettype($bindingValue)));
125126
}
126127
}
127128

‎src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveBindingsPassTest.php‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
usePHPUnit\Framework\TestCase;
1515
useSymfony\Component\DependencyInjection\Argument\BoundArgument;
16+
useSymfony\Component\DependencyInjection\Argument\TaggedIteratorArgument;
1617
useSymfony\Component\DependencyInjection\Compiler\AutowireRequiredMethodsPass;
1718
useSymfony\Component\DependencyInjection\Compiler\ResolveBindingsPass;
1819
useSymfony\Component\DependencyInjection\ContainerBuilder;
@@ -31,7 +32,10 @@ public function testProcess()
3132
{
3233
$container =newContainerBuilder();
3334

34-
$bindings = [CaseSensitiveClass::class =>newBoundArgument(newReference('foo'))];
35+
$bindings = [
36+
CaseSensitiveClass::class =>newBoundArgument(newReference('foo')),
37+
'iterable $objects' =>newBoundArgument(newTaggedIteratorArgument('tag.name'),true, BoundArgument::INSTANCEOF_BINDING),
38+
];
3539

3640
$definition =$container->register(NamedArgumentsDummy::class, NamedArgumentsDummy::class);
3741
$definition->setArguments([1 =>'123']);
@@ -44,7 +48,7 @@ public function testProcess()
4448
$pass =newResolveBindingsPass();
4549
$pass->process($container);
4650

47-
$this->assertEquals([newReference('foo'),'123'],$definition->getArguments());
51+
$this->assertEquals([0 =>newReference('foo'),1 =>'123',4 =>newTaggedIteratorArgument('tag.name')],$definition->getArguments());
4852
$this->assertEquals([['setSensitiveClass', [newReference('foo')]]],$definition->getMethodCalls());
4953
}
5054

‎src/Symfony/Component/DependencyInjection/Tests/Fixtures/NamedArgumentsDummy.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*/
1010
class NamedArgumentsDummy
1111
{
12-
publicfunction__construct(CaseSensitiveClass$c,$apiKey,$hostName,ContainerInterface$interface)
12+
publicfunction__construct(CaseSensitiveClass$c,$apiKey,$hostName,ContainerInterface$interface,iterable$objects)
1313
{
1414
}
1515

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp