Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Marc Moreram:
EventListeners as Collectors in Symfony
Aug 28, 2015 @ 13:25:07

Marc Moreram has posted a guide on his site to using event listeners as collectors in Symfony 2 based applications. He shows how to hook into the eventing system and both gather events fired (matching your criteria) and view the current collection.

Some of my concerns during the last couple of years have been how to collect data from all installed bundles using available tools in Symfony packages. I say concerns because I don’t really know if is there a tool for that. Some people have told me that the EventDispatcher component can do this work greatly, but then I have the same question once and again… is this component designed for such?

He uses an example of gathering mmoreram.wake_up events from his codebase, triggered when it "wakes up". He shows how to create a simple class for the event with a "rested" value. He modifies this to set up an array of "feelings" inside the event and a method to add new instances to the internal array. Finally he shows how to dispatch an event of the mmoreram.wake_up type and access the resulting set of "feelings" directly from the event.

tagged: event listener collector symfony feelings fire wakeup tutorial

Link: http://mmoreram.com/blog/2015/08/28/eventlisteners-as-collectors-in-symfony/


Trending Topics: