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 07e020a

Browse filesBrowse files
minor #60002 [DependencyInjection] Rename "exclude tag" to "resource tag" (kbond)
This PR was merged into the 7.3 branch. Discussion ---------- [DependencyInjection] Rename "exclude tag" to "resource tag" | Q | A | ------------- | --- | Branch? | 7.3 | Bug fix? | no | New feature? | no | Deprecations? | no | Issues | Follow up to #59704 | License | MIT I find `$definition->addExcludedTag('app.model')` and `$containerBuilder->findExcludedServiceIds('app.model')` unintuitive. If feels like your excluding something from the DI container but in fact, your registering it, but in a "different way". The fact that it's an excluded service is just a side-effect. This is especially weird when the tag has attributes (`$definition->addExcludedTag('app.model', ['connection' => 'default'])`). Totally open for a name other than "resource". Commits ------- aa91936 [DI] Rename "exclude tag" to "resource tag"
2 parents 8634b21 + aa91936 commit 07e020a
Copy full SHA for 07e020a

File tree

6 files changed

+24
-24
lines changed
Filter options

6 files changed

+24
-24
lines changed

‎src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
+7-7Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -765,24 +765,24 @@ static function (ChildDefinition $definition, AsPeriodicTask|AsCronTask $attribu
765765
}
766766

767767
$container->registerForAutoconfiguration(CompilerPassInterface::class)
768-
->addExcludeTag('container.excluded.compiler_pass');
768+
->addResourceTag('container.excluded.compiler_pass');
769769
$container->registerForAutoconfiguration(TestCase::class)
770-
->addExcludeTag('container.excluded.test_case');
770+
->addResourceTag('container.excluded.test_case');
771771
$container->registerAttributeForAutoconfiguration(AsMessage::class, static function (ChildDefinition $definition) {
772-
$definition->addExcludeTag('container.excluded.messenger.message');
772+
$definition->addResourceTag('container.excluded.messenger.message');
773773
});
774774
$container->registerAttributeForAutoconfiguration(Entity::class, static function (ChildDefinition $definition) {
775-
$definition->addExcludeTag('container.excluded.doctrine.entity');
775+
$definition->addResourceTag('container.excluded.doctrine.entity');
776776
});
777777
$container->registerAttributeForAutoconfiguration(Embeddable::class, static function (ChildDefinition $definition) {
778-
$definition->addExcludeTag('container.excluded.doctrine.embeddable');
778+
$definition->addResourceTag('container.excluded.doctrine.embeddable');
779779
});
780780
$container->registerAttributeForAutoconfiguration(MappedSuperclass::class, static function (ChildDefinition $definition) {
781-
$definition->addExcludeTag('container.excluded.doctrine.mapped_superclass');
781+
$definition->addResourceTag('container.excluded.doctrine.mapped_superclass');
782782
});
783783

784784
$container->registerAttributeForAutoconfiguration(JsonStreamable::class, static function (ChildDefinition $definition, JsonStreamable $attribute) {
785-
$definition->addExcludeTag('json_streamer.streamable', [
785+
$definition->addResourceTag('json_streamer.streamable', [
786786
'object' => $attribute->asObject,
787787
'list' => $attribute->asList,
788788
]);

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/CHANGELOG.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ CHANGELOG
77
* Make `#[AsTaggedItem]` repeatable
88
* Support `@>` as a shorthand for `!service_closure` in yaml files
99
* Don't skip classes with private constructor when autodiscovering
10-
* Add `Definition::addExcludeTag()` and `ContainerBuilder::findExcludedServiceIds()`
10+
* Add `Definition::addResourceTag()` and `ContainerBuilder::findTaggedResourceIds()`
1111
for auto-configuration of classes excluded from the service container
1212
* Leverage native lazy objects when possible for lazy services
1313

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/ContainerBuilder.php
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,9 +1356,9 @@ public function findTaggedServiceIds(string $name, bool $throwOnAbstract = false
13561356
*
13571357
* Example:
13581358
*
1359-
* $container->register('foo')->addExcludeTag('my.tag', ['hello' => 'world'])
1359+
* $container->register('foo')->addResourceTag('my.tag', ['hello' => 'world'])
13601360
*
1361-
* $serviceIds = $container->findExcludedServiceIds('my.tag');
1361+
* $serviceIds = $container->findTaggedResourceIds('my.tag');
13621362
* foreach ($serviceIds as $serviceId => $tags) {
13631363
* foreach ($tags as $tag) {
13641364
* echo $tag['hello'];
@@ -1367,14 +1367,14 @@ public function findTaggedServiceIds(string $name, bool $throwOnAbstract = false
13671367
*
13681368
* @return array<string, array> An array of tags with the tagged service as key, holding a list of attribute arrays
13691369
*/
1370-
public function findExcludedServiceIds(string $tagName): array
1370+
public function findTaggedResourceIds(string $tagName): array
13711371
{
13721372
$this->usedTags[] = $tagName;
13731373
$tags = [];
13741374
foreach ($this->getDefinitions() as $id => $definition) {
13751375
if ($definition->hasTag($tagName)) {
13761376
if (!$definition->hasTag('container.excluded')) {
1377-
throw new InvalidArgumentException(\sprintf('The service "%s" tagged "%s" is missing the "container.excluded" tag.', $id, $tagName));
1377+
throw new InvalidArgumentException(\sprintf('The resource "%s" tagged "%s" is missing the "container.excluded" tag.', $id, $tagName));
13781378
}
13791379
$tags[$id] = $definition->getTag($tagName);
13801380
}

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Definition.php
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -456,13 +456,13 @@ public function addTag(string $name, array $attributes = []): static
456456
}
457457

458458
/**
459-
* Adds a tag to the definition and marks it as excluded.
459+
* Adds a "resource" tag to the definition and marks it as excluded.
460460
*
461-
* These definitions should be processed using {@see ContainerBuilder::findExcludedServiceIds()}
461+
* These definitions should be processed using {@see ContainerBuilder::findTaggedResourceIds()}
462462
*
463463
* @return $this
464464
*/
465-
public function addExcludeTag(string $name, array $attributes = []): static
465+
public function addResourceTag(string $name, array $attributes = []): static
466466
{
467467
return $this->addTag($name, $attributes)
468468
->addTag('container.excluded', ['source' => \sprintf('by tag "%s"', $name)])

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php
+7-7Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,21 +1095,21 @@ public function testFindTaggedServiceIdsThrowsWhenAbstract()
10951095
$builder->findTaggedServiceIds('foo', true);
10961096
}
10971097

1098-
public function testFindExcludedServiceIds()
1098+
public function testFindTaggedResourceIds()
10991099
{
11001100
$builder = new ContainerBuilder();
11011101
$builder->register('myservice', 'Bar\FooClass')
11021102
->addTag('foo', ['foo' => 'foo'])
11031103
->addTag('bar', ['bar' => 'bar'])
11041104
->addTag('foo', ['foofoo' => 'foofoo'])
1105-
->addExcludeTag('container.excluded');
1105+
->addResourceTag('container.excluded');
11061106

11071107
$expected = ['myservice' => [['foo' => 'foo'], ['foofoo' => 'foofoo']]];
1108-
$this->assertSame($expected, $builder->findExcludedServiceIds('foo'));
1109-
$this->assertSame([], $builder->findExcludedServiceIds('foofoo'));
1108+
$this->assertSame($expected, $builder->findTaggedResourceIds('foo'));
1109+
$this->assertSame([], $builder->findTaggedResourceIds('foofoo'));
11101110
}
11111111

1112-
public function testFindExcludedServiceIdsThrowsWhenNotExcluded()
1112+
public function testFindTaggedResourceIdsThrowsWhenNotExcluded()
11131113
{
11141114
$builder = new ContainerBuilder();
11151115
$builder->register('myservice', 'Bar\FooClass')
@@ -1118,8 +1118,8 @@ public function testFindExcludedServiceIdsThrowsWhenNotExcluded()
11181118
->addTag('foo', ['foofoo' => 'foofoo']);
11191119

11201120
$this->expectException(InvalidArgumentException::class);
1121-
$this->expectExceptionMessage('The service "myservice" tagged "foo" is missing the "container.excluded" tag.');
1122-
$builder->findExcludedServiceIds('foo', true);
1121+
$this->expectExceptionMessage('The resource "myservice" tagged "foo" is missing the "container.excluded" tag.');
1122+
$builder->findTaggedResourceIds('foo');
11231123
}
11241124

11251125
public function testFindUnusedTags()

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/DefinitionTest.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,10 +258,10 @@ public function testTags()
258258
], $def->getTags(), '->getTags() returns all tags');
259259
}
260260

261-
public function testAddExcludeTag()
261+
public function testAddResourceTag()
262262
{
263263
$def = new Definition('stdClass');
264-
$def->addExcludeTag('foo', ['bar' => true]);
264+
$def->addResourceTag('foo', ['bar' => true]);
265265

266266
$this->assertSame([['bar' => true]], $def->getTag('foo'));
267267
$this->assertTrue($def->isAbstract());

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.