8000 [DependencyInjection] Rename "exclude tag" to "resource tag" by kbond · Pull Request #60002 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[DependencyInjection] Rename "exclude tag" to "resource tag" #60002

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]);
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/DependencyInjection/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand All @@ -1367,14 +1367,14 @@ public function findTaggedServiceIds(string $name, bool $throwOnAbstract = false
*
* @return array<string, 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);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Symfony/Component/DependencyInjection/Definition.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Loading
0