6

Now I can tag services eg: form.type witch informs forms component to use this service as form type.

I can't find any documentation on this, how can I define my own tag? And get all services that are tagged with it? Or even pass all tagged with my tag services as a argument to another service?

1 Answer 1

10

OK I found answer, basically tags are processed by classes that implements CompilerPassInterface compiler pass objects can be added in bunlde file (eg: Symfony\Bundle\FrameworkBundle\FrameworkBundle see method build)

CompilerPass have method process witch receives ContainerBuilder as argument.
ContainerBuilder has method: findTaggedServiceIds, witch can be used to get tagged services IDs, and do whatever you want with them.

To pass results to another service you have to define empty collection argument for it, and using ContainerBuilder replace this argument with found service IDs.

eg: Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\FormPass

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for sharing the answer. But what did you need this for? I never used this

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.