Description
Symfony version(s) affected
6.0
Description
If we use an abstract service and extend a class from it with an alias in the name and specifying the class attribute, and write the tags attribute in the descendant, then when building the cache after calling the findTaggedServiceIds method, it returns duplicated tags: one for the alias and one for the full class path.
How to reproduce
services.yaml
app.processor:
class: App\Processor\AbstractProcessor
abstract: true
calls:
- setLogger: [ '@logger' ]
- setSerializer: [ '@jms_serializer' ]
app.processor.base:
class: App\Processor\BaseProcessor
parent: app.processor
tags:
- {name: 'enqueue.topic_subsciber', client: 'base' }
I used vendor/enqueue/enqueue/Symfony/Client/DependencyInjection/BuildTopicSubscriberRoutesPass.php (file of enqueue/enqueue package) for reproducing it, but it does not big matter, it just my case.
$tag = 'enqueue.topic_subscriber';
$routeCollection = new RouteCollection([]);
$tags = $container->findTaggedServiceIds($tag);
dd($tags);
In result i have:
^ array:2 [
"App\Processor\BaseProcessor" => array:1 [
0 => array:1 [
"client" => "base"
]
]
"app.processor.base" => array:1 [
0 => array:1 [
"client" => "base"
]
]
]
Which creates an incorrect amount of $routeCollection, because there is no information in the result data that it is the same class.
But if we did not use aliases:
services.yaml
app.processor:
class: App\Processor\AbstractProcessor
abstract: true
calls:
- setLogger: [ '@logger' ]
- setSerializer: [ '@jms_serializer' ]
App\Processor\BaseProcessor:
parent: app.processor
tags:
- {name: 'enqueue.topic_subsciber', client: 'base' }
Then count of tagged classes will be correct:
^ array:1 [
"App\Processor\BaseProcessor" => array:1 [
0 => array:1 [
"client" => "base"
]
]
]
May be its not fault of abstract class. But i did not checked it fully.
Possible Solution
Some how exclude duplicates and leave only tagged aliases.
Additional Context
No response