Reputation: 596
I have a symfony2 bundle that has an event, how can I get multiple other bundles to listen for that event?
Ie. how can I pass my dispatcher between bundles?
Upvotes: 3
Views: 970
Reputation: 17678
Use the event_dispatcher
service instead of defining your own.
For example, if you're using YAML configuration files and are defining a custom service that will dispatch events, declare "@event_dispatcher"
as an argument to your service.
From a controller, you can use $this->container->get('event_dispatcher');
to accomplish the same thing.
All the framework internals use this provided service, and all bundles that want to fire or listen to events globally should use it as well.
Upvotes: 4