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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With