-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DependencyInjection] Simplify using DI attributes with ServiceLocator/Iterator
's
#51916
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
[DependencyInjection] Simplify using DI attributes with ServiceLocator/Iterator
's
#51916
Conversation
ServiceLocator/Iterator
'sServiceLocator/Iterator
's
The current implementation restricts the usage to just |
src/Symfony/Component/DependencyInjection/Attribute/AutowireIterator.php
Outdated
Show resolved
Hide resolved
Making But we could make RegisterServiceSubscribersPass aware of
Nope as you spotted. |
7c0d807
to
33169fe
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I pushed some changes, let's wait for tests and GTM.
|
||
$references = []; | ||
|
||
foreach ($services as $key => $type) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've moved this logic to AutowireLocator: while working on this PR, I realized that it doesn't make sense to support AutowireLocator([FooInterface::class])
. People that really want a static iterable as default can use Autowire([new Autowire(FooInterface::class)])
instead.
$attributes = []; | ||
|
||
if ($type instanceof Autowire) { | ||
$references[$key] = $type; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need for more here, AutowirePass will turn that into a TypedReference on its own
@@ -78,6 +79,11 @@ protected function processValue(mixed $value, bool $isRoot = false): mixed | ||
foreach ($class::getSubscribedServices() as $key => $type) { | ||
$attributes = []; | ||
|
||
if (!isset($serviceMap[$key]) && $type instanceof Autowire) { | ||
$subscriberMap[$key] = $type; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding support for new Autowire
being returned by getSubscribedServices
, for consistency, altough it's not in contracts, it might still be convenient.
@@ -63,7 +63,6 @@ | ||
"symfony/http-client-contracts": "<2.5", | ||
"symfony/mailer": "<5.4", | ||
"symfony/messenger": "<5.4", | ||
"symfony/service-contracts": "<3.2", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as requested, since this is an optional feature
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👏 thanks!
Thanks for finalizing! |
This PR was merged into the 6.4 branch. Discussion ---------- [DependencyInjection] Fix PhpDoc type | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | no | New feature? | no | Deprecations? | no | Issues | - | License | MIT Was added in #51916. Commits ------- b533c7d [DependencyInjection] Fix PhpDoc type
Instead of:
This PR allows: