Skip to content
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

[Feature Request] Tagged iterators without tags! #53090

Closed
sylfabre opened this issue Dec 15, 2023 · 3 comments
Closed

[Feature Request] Tagged iterators without tags! #53090

sylfabre opened this issue Dec 15, 2023 · 3 comments

Comments

@sylfabre
Copy link
Contributor

sylfabre commented Dec 15, 2023

Description

I use tagged iterators mostly to autowire implementations of a given interface as an iterable.

#[AutoconfigureTag('app.some_tag')]
interface SomeInterface
{
    ...
}

class SomeService
{
    public function __construct(
        /** @var SomeInterface[] */
        #[TaggedIterator('app.some_tag')]
        protected iterable $somes
    ) {
    }
}

It works great 👍
And I understand I have to provide a tag because this is how the system works today ✅
And I understand that the tag may be useful for other use cases ✅
However, from a developer's POV, I don't care about what this tag is 99% of the time so I would like it to be optional.

Example

It would be amazing if this simpler code was working 🤩

class SomeService
{
    public function __construct(
        /** @var SomeInterface[] */
        #[InterfaceIterator(SomeInterface::class)]
        protected iterable $somes
    ) {
    }
}

Or if it makes it easier to implement

#[AutoconfigureForIterable]
interface SomeInterface
{
    ...
}
class SomeService
{
    public function __construct(
        /** @var SomeInterface[] */
        #[InterfaceIterator(SomeInterface::class)]
        protected iterable $somes
    ) {
    }
}
@valtzu
Copy link
Contributor

valtzu commented Dec 16, 2023

This seems to already be working, tested on 6.4:

#[AutoconfigureTag]
interface SomeInterface
{
    ...
}

class SomeService
{
    public function __construct(
        /** @var SomeInterface[] */
        #[TaggedIterator(SomeInterface::class)]
        protected iterable $somes
    ) {
    }
}

From the original #[AutoconfigureTag] PR #39804:

The name of the tag is optional and defaults to the name of the tagged type (typically the FQCN of an interface). This should ease with writing locators/iterators of tagged services.

@derrabus
Copy link
Member

Closing as explained. ✌️

@derrabus derrabus closed this as not planned Won't fix, can't repro, duplicate, stale Dec 16, 2023
@sylfabre
Copy link
Contributor Author

Thanks @valtzu

This is not documented, I'll try to work on a PR some day

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants