-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DependencyInjection] Add #[AutowireIterator]
attribute and improve #[AutowireLocator]
#51832
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
Conversation
8b9073c
to
ed3efda
Compare
src/Symfony/Component/DependencyInjection/Attribute/AutowireIterator.php
Show resolved
Hide resolved
src/Symfony/Component/DependencyInjection/Tests/Compiler/IntegrationTest.php
Outdated
Show resolved
Hide resolved
17a9a15
to
8ed9318
Compare
PR updated and ready. Big Hurray to @kbond for the tests 🙏 🤗 |
TaggedIterator and TaggedLocator attributes are they still use full? |
@KerianMM that's an open question. I see no hurry in deprecating them, I'd be fine waiting for 7.1. |
7bb9a9e
to
38c48ef
Compare
src/Symfony/Component/DependencyInjection/Attribute/AutowireIterator.php
Show resolved
Hide resolved
src/Symfony/Component/DependencyInjection/Attribute/AutowireIterator.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/DependencyInjection/Attribute/AutowireIterator.php
Show resolved
Hide resolved
Why not improving the existing attributes instead of adding new ones ? |
src/Symfony/Component/DependencyInjection/Attribute/AutowireLocator.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/DependencyInjection/Attribute/AutowireIterator.php
Show resolved
Hide resolved
src/Symfony/Component/DependencyInjection/Attribute/AutowireIterator.php
Show resolved
Hide resolved
38c48ef
to
c262b32
Compare
Because I think it's important to push the |
👍 to do it on 7.1 and give time to people having them since 5.3. The docs should probably recommend the new ones asap though |
I updated the syntax for |
Can you add a code example please? Thanks |
What's in ServiceSubscriberInterface: symfony/src/Symfony/Contracts/Service/ServiceSubscriberInterface.php Lines 53 to 57 in d27190a
|
Updated |
c262b32
to
fe8d9dc
Compare
fe8d9dc
to
a87f2e0
Compare
Thank you @kbond. |
…ator]` and add `#[AutowireIterator]` (OskarStark) This PR was squashed before being merged into the 6.4 branch. Discussion ---------- [DependencyInjection] Update syntax for `#[AutowireLocator]` and add `#[AutowireIterator]` cc `@kbond` Waiting code merge * symfony/symfony#51832 Fixes #18997 Commits ------- 528cbda [DependencyInjection] Update syntax for `#[AutowireLocator]` and add `#[AutowireIterator]`
@@ -63,6 +63,7 @@ | |||
"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.
@kbond why was this added? is there a way to remove this conflict?
this makes it not possible for us to upgrade to symfony 6.4 because this forces a requirement for psr/container ^2.0
, and we are still on v1 because the latest version of laminas/laminas-servicemanager
requires v1:
https://github.com/laminas/laminas-servicemanager/blob/3.23.x/composer.json#L26
this is sort of the same issue as api-platform/core#5811
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.
/cc @nicolas-grekas
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.
Sorry @kbond, tagged you as it looked like your commit.
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.
This is needed because the test case uses the $type argument of SubscribedService, which exists since 3.2.
PR welcome to change the test case and relax this.
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
|
||
if ($type instanceof SubscribedService) { | ||
$key = $type->key ?? $key; | ||
$attributes = $type->attributes; |
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.
symfony/dependency-injection
requires "symfony/service-contracts": "^2.5|^3.0
, but attributes
, nullable
and type
are not defined on SubscribedService
in until 3.2.
is this a mistake?
…d `#[TaggedLocator]` (GromNaN) This PR was merged into the 7.1 branch. Discussion ---------- [DependencyInjection] Deprecate `#[TaggedIterator]` and `#[TaggedLocator]` | Q | A | ------------- | --- | Branch? | 7.1 | Bug fix? | no | New feature? | no | Deprecations? | yes | Issues | Planned in #51832 | License | MIT `#[TaggedIterator]` and `#[TaggedLocator]` attributes are replaced by `#[AutowireIterator]` and `#[AutowireLocator]`, for naming consistency with all `#[Autowire*]` attributes. Commits ------- 4bc6bed Deprecate #[TaggedIterator] and #[TaggedLocator]
This PR is building on #51392 to add an
#[AutowireIterator]
attribute and improve#[AutowireLocator]
.The new
#[AutowireIterator]
attribute can be used to describe what#[AutowireLocator]
can do, except that we get an iterator instead of a container.And
#[AutowireLocator]
can now be used instead of#[TaggedLocator]
:#[AutowireLocator('foo')]
and done.In order to describe that you want a list of services, we cannot use named arguments anymore so we have to pass an array now:
#[AutowireLocator(['foo' => 'F', 'bar' => 'B'])]
should be used instead of#[AutowireLocator(foo: 'F', bar: 'B')]
.Last but not least, this adds support for nesting
SubscribedService
objects in the list of described services. This provides feature-parity with what we can do when implementingServiceSubscriberInterface
.I didn't deprecate
TaggedIterator
norTaggedLocator
. We could, but maybe we should wait for 7.1?TODO:
PS: while writing this, I realize that we may merge both tags in one, and letAutowirePass
decide if it should build a locator or an iterator based on the type of the argument that has the attribute. We'd "just" need to find a name that'd work for that.