-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Closed
Description
Symfony version(s) affected
5.4 - 7.1.0-rc1
Description
When the attribute Autoconfigure
is used multiple times on the same class, only the last instance is used, other seems to be ignored.
How to reproduce
use Symfony\Component\DependencyInjection\Attribute\Autoconfigure;
#[Autoconfigure(lazy: true)]
#[Autoconfigure(shared: false)]
interface MyInterface {}
class MyClass implements MyInterface {}
$ bin/console debug:container MyClass
Information for Service "App\MyClass"
=====================================
---------------- -----------------
Option Value
---------------- -----------------
Service ID App\MyClass
Class App\MyClass
Tags -
Public no
Synthetic no
Lazy no <- Default value from the 2nd attribute, ignoring the value set in the 1st attribute
Shared no <- Value set in the 2nd attribute
Abstract no
Autowired yes
Autoconfigured yes
Usages App\MyInterface
---------------- -----------------
If the order of the attribute is modified:
use Symfony\Component\DependencyInjection\Attribute\Autoconfigure;
#[Autoconfigure(shared: false)]
#[Autoconfigure(lazy: true)]
interface MyInterface {}
❯ bin/console debug:container MyClass
Information for Service "App\MyClass"
=====================================
---------------- -----------------
Option Value
---------------- -----------------
Service ID App\MyClass
Class App\MyClass
Tags -
Public no
Synthetic no
Lazy yes <- Value set in the 2nd attribute
Shared yes <- Default value from the 2nd attribute, ignoring the value set in the 1st attribute
Abstract no
Autowired yes
Autoconfigured yes
Usages App\MyInterface
---------------- -----------------
Possible Solution
Remove null
values when the attribute is loaded:
symfony/src/Symfony/Component/DependencyInjection/Compiler/RegisterAutoconfigureAttributesPass.php
Line 86 in b8b3c39
$class->name => [$container->registerForAutoconfiguration($class->name)] + $attribute, |
Additional Context
No response
tourze