[DependencyInjection] Add #[AutowireIterator] attribute and improve #[AutowireLocator]#51832
Conversation
8b9073c to
ed3efda
Compare
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
|
Why not improving the existing attributes instead of adding new ones ? |
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]`
| "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.
@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.
Sorry @kbond, tagged you as it looked like your commit.
There was a problem hiding this comment.
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.
|
|
||
| if ($type instanceof SubscribedService) { | ||
| $key = $type->key ?? $key; | ||
| $attributes = $type->attributes; |
There was a problem hiding this comment.
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]
…#[TaggedLocator]` attributes (GromNaN) This PR was merged into the 8.0 branch. Discussion ---------- [DependencyInjection] Remove `#[TaggedIterator]` and `#[TaggedLocator]` attributes | Q | A | ------------- | --- | Branch? | 8.0 | Bug fix? | no | New feature? | yes | Deprecations? | no | Issues | - | License | MIT The new attributes `#[AutowireLocator]` and `#[AutowireIterator]` were introduced in Symfony 6.4 by #51392 and #51832. These replace the previous attributes `#[TaggedIterator]` and `#[TaggedLocator]` which were introduced in Symfony 5.4 by #40406 and subsequently deprecated in 7.1 by #54371 Commits ------- c096714 Remove TaggedIterator and TaggedLocator attributes
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
SubscribedServiceobjects in the list of described services. This provides feature-parity with what we can do when implementingServiceSubscriberInterface.I didn't deprecate
TaggedIteratornorTaggedLocator. 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 letAutowirePassdecide 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.