From aa919360f811da5d2da4b0e36f0be80cd3591525 Mon Sep 17 00:00:00 2001 From: Kevin Bond Date: Tue, 18 Mar 2025 20:37:55 -0400 Subject: [PATCH] [DI] Rename "exclude tag" to "resource tag" --- .../DependencyInjection/FrameworkExtension.php | 14 +++++++------- .../Component/DependencyInjection/CHANGELOG.md | 2 +- .../DependencyInjection/ContainerBuilder.php | 8 ++++---- .../Component/DependencyInjection/Definition.php | 6 +++--- .../Tests/ContainerBuilderTest.php | 14 +++++++------- .../DependencyInjection/Tests/DefinitionTest.php | 4 ++-- 6 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index 9ee0f0f43441a..2860457a8e302 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -765,24 +765,24 @@ static function (ChildDefinition $definition, AsPeriodicTask|AsCronTask $attribu } $container->registerForAutoconfiguration(CompilerPassInterface::class) - ->addExcludeTag('container.excluded.compiler_pass'); + ->addResourceTag('container.excluded.compiler_pass'); $container->registerForAutoconfiguration(TestCase::class) - ->addExcludeTag('container.excluded.test_case'); + ->addResourceTag('container.excluded.test_case'); $container->registerAttributeForAutoconfiguration(AsMessage::class, static function (ChildDefinition $definition) { - $definition->addExcludeTag('container.excluded.messenger.message'); + $definition->addResourceTag('container.excluded.messenger.message'); }); $container->registerAttributeForAutoconfiguration(Entity::class, static function (ChildDefinition $definition) { - $definition->addExcludeTag('container.excluded.doctrine.entity'); + $definition->addResourceTag('container.excluded.doctrine.entity'); }); $container->registerAttributeForAutoconfiguration(Embeddable::class, static function (ChildDefinition $definition) { - $definition->addExcludeTag('container.excluded.doctrine.embeddable'); + $definition->addResourceTag('container.excluded.doctrine.embeddable'); }); $container->registerAttributeForAutoconfiguration(MappedSuperclass::class, static function (ChildDefinition $definition) { - $definition->addExcludeTag('container.excluded.doctrine.mapped_superclass'); + $definition->addResourceTag('container.excluded.doctrine.mapped_superclass'); }); $container->registerAttributeForAutoconfiguration(JsonStreamable::class, static function (ChildDefinition $definition, JsonStreamable $attribute) { - $definition->addExcludeTag('json_streamer.streamable', [ + $definition->addResourceTag('json_streamer.streamable', [ 'object' => $attribute->asObject, 'list' => $attribute->asList, ]); diff --git a/src/Symfony/Component/DependencyInjection/CHANGELOG.md b/src/Symfony/Component/DependencyInjection/CHANGELOG.md index 0551fadb23e8a..1021c0a25423f 100644 --- a/src/Symfony/Component/DependencyInjection/CHANGELOG.md +++ b/src/Symfony/Component/DependencyInjection/CHANGELOG.md @@ -7,7 +7,7 @@ CHANGELOG * Make `#[AsTaggedItem]` repeatable * Support `@>` as a shorthand for `!service_closure` in yaml files * Don't skip classes with private constructor when autodiscovering - * Add `Definition::addExcludeTag()` and `ContainerBuilder::findExcludedServiceIds()` + * Add `Definition::addResourceTag()` and `ContainerBuilder::findTaggedResourceIds()` for auto-configuration of classes excluded from the service container * Leverage native lazy objects when possible for lazy services diff --git a/src/Symfony/Component/DependencyInjection/ContainerBuilder.php b/src/Symfony/Component/DependencyInjection/ContainerBuilder.php index f5270e31ae076..8197b104c6bd7 100644 --- a/src/Symfony/Component/DependencyInjection/ContainerBuilder.php +++ b/src/Symfony/Component/DependencyInjection/ContainerBuilder.php @@ -1356,9 +1356,9 @@ public function findTaggedServiceIds(string $name, bool $throwOnAbstract = false * * Example: * - * $container->register('foo')->addExcludeTag('my.tag', ['hello' => 'world']) + * $container->register('foo')->addResourceTag('my.tag', ['hello' => 'world']) * - * $serviceIds = $container->findExcludedServiceIds('my.tag'); + * $serviceIds = $container->findTaggedResourceIds('my.tag'); * foreach ($serviceIds as $serviceId => $tags) { * foreach ($tags as $tag) { * echo $tag['hello']; @@ -1367,14 +1367,14 @@ public function findTaggedServiceIds(string $name, bool $throwOnAbstract = false * * @return array An array of tags with the tagged service as key, holding a list of attribute arrays */ - public function findExcludedServiceIds(string $tagName): array + public function findTaggedResourceIds(string $tagName): array { $this->usedTags[] = $tagName; $tags = []; foreach ($this->getDefinitions() as $id => $definition) { if ($definition->hasTag($tagName)) { if (!$definition->hasTag('container.excluded')) { - throw new InvalidArgumentException(\sprintf('The service "%s" tagged "%s" is missing the "container.excluded" tag.', $id, $tagName)); + throw new InvalidArgumentException(\sprintf('The resource "%s" tagged "%s" is missing the "container.excluded" tag.', $id, $tagName)); } $tags[$id] = $definition->getTag($tagName); } diff --git a/src/Symfony/Component/DependencyInjection/Definition.php b/src/Symfony/Component/DependencyInjection/Definition.php index 682540e91a289..61cc0b9d6785c 100644 --- a/src/Symfony/Component/DependencyInjection/Definition.php +++ b/src/Symfony/Component/DependencyInjection/Definition.php @@ -456,13 +456,13 @@ public function addTag(string $name, array $attributes = []): static } /** - * Adds a tag to the definition and marks it as excluded. + * Adds a "resource" tag to the definition and marks it as excluded. * - * These definitions should be processed using {@see ContainerBuilder::findExcludedServiceIds()} + * These definitions should be processed using {@see ContainerBuilder::findTaggedResourceIds()} * * @return $this */ - public function addExcludeTag(string $name, array $attributes = []): static + public function addResourceTag(string $name, array $attributes = []): static { return $this->addTag($name, $attributes) ->addTag('container.excluded', ['source' => \sprintf('by tag "%s"', $name)]) diff --git a/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php b/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php index 304cd3e4dc5b1..ccae8c30ee261 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php @@ -1095,21 +1095,21 @@ public function testFindTaggedServiceIdsThrowsWhenAbstract() $builder->findTaggedServiceIds('foo', true); } - public function testFindExcludedServiceIds() + public function testFindTaggedResourceIds() { $builder = new ContainerBuilder(); $builder->register('myservice', 'Bar\FooClass') ->addTag('foo', ['foo' => 'foo']) ->addTag('bar', ['bar' => 'bar']) ->addTag('foo', ['foofoo' => 'foofoo']) - ->addExcludeTag('container.excluded'); + ->addResourceTag('container.excluded'); $expected = ['myservice' => [['foo' => 'foo'], ['foofoo' => 'foofoo']]]; - $this->assertSame($expected, $builder->findExcludedServiceIds('foo')); - $this->assertSame([], $builder->findExcludedServiceIds('foofoo')); + $this->assertSame($expected, $builder->findTaggedResourceIds('foo')); + $this->assertSame([], $builder->findTaggedResourceIds('foofoo')); } - public function testFindExcludedServiceIdsThrowsWhenNotExcluded() + public function testFindTaggedResourceIdsThrowsWhenNotExcluded() { $builder = new ContainerBuilder(); $builder->register('myservice', 'Bar\FooClass') @@ -1118,8 +1118,8 @@ public function testFindExcludedServiceIdsThrowsWhenNotExcluded() ->addTag('foo', ['foofoo' => 'foofoo']); $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('The service "myservice" tagged "foo" is missing the "container.excluded" tag.'); - $builder->findExcludedServiceIds('foo', true); + $this->expectExceptionMessage('The resource "myservice" tagged "foo" is missing the "container.excluded" tag.'); + $builder->findTaggedResourceIds('foo'); } public function testFindUnusedTags() diff --git a/src/Symfony/Component/DependencyInjection/Tests/DefinitionTest.php b/src/Symfony/Component/DependencyInjection/Tests/DefinitionTest.php index 1a51c9af395c1..459e566d22661 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/DefinitionTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/DefinitionTest.php @@ -258,10 +258,10 @@ public function testTags() ], $def->getTags(), '->getTags() returns all tags'); } - public function testAddExcludeTag() + public function testAddResourceTag() { $def = new Definition('stdClass'); - $def->addExcludeTag('foo', ['bar' => true]); + $def->addResourceTag('foo', ['bar' => true]); $this->assertSame([['bar' => true]], $def->getTag('foo')); $this->assertTrue($def->isAbstract());