Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[DI][RFC] Allow to check the class of the tagged collection's item #32815

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

Closed
vudaltsov opened this issue Jul 30, 2019 · 2 comments
Closed

[DI][RFC] Allow to check the class of the tagged collection's item #32815

vudaltsov opened this issue Jul 30, 2019 · 2 comments
Labels
DependencyInjection RFC RFC = Request For Comments (proposals about features that you want to be discussed)

Comments

@vudaltsov
Copy link
Contributor

Since #30257 we can inject complex tagged collections easily.

The only thing left before PHP gets generics is compile-time checking of the collection item type.

The syntax I propose:

services:
    foo_service:
        class: Foo
        tags:
            - foo

    bar:
        class: Bar
        arguments:
            - !tagged
                tag: foo
                # new attribute
                instanceof: FooInterface

Note that having the foo tag does not imply being an instance of FooInterface.

@vudaltsov vudaltsov changed the title [DependencyInjection][RFC] Allow to check the class of the tagged collection's item [DI][RFC] Allow to check the class of the tagged collection's item Jul 30, 2019
@yceruto yceruto added DependencyInjection RFC RFC = Request For Comments (proposals about features that you want to be discussed) labels Jul 30, 2019
@nicolas-grekas
Copy link
Member

That doesn't belong to the container to me. Actually, no type checks belong to the container. E.g. you can inject a logger where a cache pool is expected and the container will happily do it. That's normal to me, each layer its responsibilities.

@vudaltsov
Copy link
Contributor Author

Agree with you, that makes sense.
Also realized that even with generics PHP will be checking that at runtime.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DependencyInjection RFC RFC = Request For Comments (proposals about features that you want to be discussed)
Projects
None yet
Development

No branches or pull requests

3 participants