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

Commit599c55d

Browse files
committed
[DependencyInjection] Option to accept excluded tags in findTaggedServiceIds
1 parent04551ad commit599c55d

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ CHANGELOG
66

77
* Make`#[AsTaggedItem]` repeatable
88
* Support`@>` as a shorthand for`!service_closure` in yaml files
9+
* Add`ContainerBuilder::findTaggedServiceIds()` 3rd argument to return excluded services
910

1011
7.2
1112
---

‎src/Symfony/Component/DependencyInjection/ContainerBuilder.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,14 +1333,21 @@ private function doResolveServices(mixed $value, array &$inlineServices = [], bo
13331333
* }
13341334
* }
13351335
*
1336+
* @param bool $notExcluded Whether to include or exclude services with the "container.excluded" tag
1337+
*
13361338
* @return array<string, array> An array of tags with the tagged service as key, holding a list of attribute arrays
13371339
*/
1338-
publicfunctionfindTaggedServiceIds(string$name,bool$throwOnAbstract =false):array
1340+
publicfunctionfindTaggedServiceIds(string$name,bool$throwOnAbstract =false,/* bool $notExcluded = true */):array
13391341
{
1342+
$notExcluded =func_num_args() >2 ?func_get_arg(2) :true;
1343+
if (!is_bool($notExcluded)) {
1344+
thrownew \TypeError(sprintf('Argument 3 passed to %s() must be of the type bool, %s given.',__METHOD__,get_debug_type($notExcluded)));
1345+
}
1346+
13401347
$this->usedTags[] =$name;
13411348
$tags = [];
13421349
foreach ($this->getDefinitions()as$id =>$definition) {
1343-
if ($definition->hasTag($name) &&!$definition->hasTag('container.excluded')) {
1350+
if ($definition->hasTag($name) &&(!$notExcluded || !$definition->hasTag('container.excluded'))) {
13441351
if ($throwOnAbstract &&$definition->isAbstract()) {
13451352
thrownewInvalidArgumentException(\sprintf('The service "%s" tagged "%s" must not be abstract.',$id,$name));
13461353
}

‎src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,6 +1067,7 @@ public function testfindTaggedServiceIds()
10671067
$builder =newContainerBuilder();
10681068
$builder
10691069
->register('foo','Bar\FooClass')
1070+
->setAbstract(true)
10701071
->addTag('foo', ['foo' =>'foo'])
10711072
->addTag('bar', ['bar' =>'bar'])
10721073
->addTag('foo', ['foofoo' =>'foofoo'])
@@ -1083,6 +1084,17 @@ public function testfindTaggedServiceIds()
10831084
],
10841085
],$builder->findTaggedServiceIds('foo'),'->findTaggedServiceIds() returns an array of service ids and its tag attributes');
10851086
$this->assertEquals([],$builder->findTaggedServiceIds('foobar'),'->findTaggedServiceIds() returns an empty array if there is annotated services');
1087+
$this->assertEquals([
1088+
'foo' => [
1089+
['foo' =>'foo'],
1090+
['foofoo' =>'foofoo'],
1091+
],
1092+
'bar' => [[]]
1093+
],$builder->findTaggedServiceIds('foo',false,false),'->findTaggedServiceIds() car include excluded services');
1094+
1095+
$this->expectException(InvalidArgumentException::class);
1096+
$this->expectExceptionMessage('The service "foo" tagged "foo" must not be abstract.');
1097+
$builder->findTaggedServiceIds('foo',true);
10861098
}
10871099

10881100
publicfunctiontestFindUnusedTags()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp