-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DependencyInjection] add #[AutowireLocator]
attribute
#51392
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
33dcf38
to
5f93604
Compare
src/Symfony/Component/DependencyInjection/Attribute/Locator.php
Outdated
Show resolved
Hide resolved
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.
Love it, I didn't expect the implementation to be so simple :)
src/Symfony/Component/DependencyInjection/Attribute/Locator.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/DependencyInjection/Attribute/Locator.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/DependencyInjection/Attribute/Locator.php
Outdated
Show resolved
Hide resolved
In order to address the failing Psalm job, I've opened #51395. |
#[Locator]
attribute#[AutowireLocator]
attribute
7d2e338
to
0e0583f
Compare
I'm wondering how we could make these work: #[AutowireLocator([
'cache' => new SubscribedService(type: CacheInterface::class: attributes: [new Target('my.cache')]),
'blobs' => new TaggedLocator('blob'),
)]
ContainerInterface $container, Any idea? |
I thought that too! I was going to take a look at this possibility after this was merged. BTW, your example can't be an array, it needs to be: #[AutowireLocator(
cache: new SubscribedService(type: CacheInterface::class: attributes: [new Target('my.cache')]),
blobs: new TaggedLocator('blob'),
)]
ContainerInterface $container, (just making sure you're ok with this syntax) |
I just noticed the failures on high+low deps, can you please have a look? |
I believe the test suite will be fixed once merged because of the http-kernel's requirement on this |
7587b15
to
3028d76
Compare
3028d76
to
5fa830d
Compare
Thank you @kbond. |
…ute and improve `#[AutowireLocator]` (nicolas-grekas, kbond) This PR was merged into the 6.4 branch. Discussion ---------- [DependencyInjection] Add `#[AutowireIterator]` attribute and improve `#[AutowireLocator]` | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | - | License | MIT 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 implementing `ServiceSubscriberInterface`. I didn't deprecate `TaggedIterator` nor `TaggedLocator`. We could, but maybe we should wait for 7.1? TODO: - [x] add tests - thanks `@kbond`! ~PS: while writing this, I realize that we may merge both tags in one, and let `AutowirePass` 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.~ Commits ------- a87f2e0 [DependencyInjection] Add tests for `AutowireLocator`/`AutowireIterator` 78018de [DependencyInjection] Add `#[AutowireIterator]` attribute and improve `#[AutowireLocator]`
…#[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
The
AutowireLocator
attribute allows configuring service locators inline:You can customize the key and have optional services: