Skip to end of metadata
Go to start of metadata

Redirection Notice

This page will redirect to in about 2 seconds.


Working with Events

A good practice in designing an application is making use of componentization and loose coupling. Ideally, components should have no knowledge of other components except for their interface or events. This makes it possible to re-use components over different applications or to swap out components with other implementations. Symfony2 has the EventDispatcher component that allow your application components to communicate with each other by dispatching events and listening to them.

Completion and Navigation for Events

When dispatching or subscribing to events, we always need to pass the event name to the relevant functions. PhpStorm comes with completion (Ctrl+Space) for event names for these parameters.

To implement EventSubscriberInterface, we need to return an array of all events we're subscribing to, as well as the functions that will handle these events. Completion is available for event names here as well.

By hovering over the event name and pressing Ctrl+Click (or CMD+Click on Mac OS X), we can navigate to all classes that use the same event name. We can also do this by placing the cursor on the event name and pressing Ctrl+B (or CMD+B on Mac OS X).


  • No labels