Subscribe to PHP Freaks RSS

TutsPlus.com: How to Use the Symfony Event Dispatcher for PHP

syndicated from www.phpdeveloper.org on October 29, 2018

The TutsPlus.com site has posted another tutorial where they go in-depth with one of the components of the Symfony framework. In this new tutorial they cover the Symfony Event Dispatcher component including its basic use via events and subscribers.

Today, we're going to learn how to use the Symfony event dispatcher component, which allows you to create events and listeners in your PHP applications. Thus, different components of your application can talk to each other with loosely coupled code.

[...] The event dispatcher component provides three elements that you could build your app architecture around: event, listener, and dispatcher. The whole system is orchestrated by the dispatcher class, which raises events at appropriate points in an application and calls listeners associated with those events.

The tutorial starts with the command you'll need to get the dispatcher installed and examples of:

  • creating events
  • dispatching the events to subscribers
  • listening for the events

The tutorial then covers subscribers, reusable listeners that can be added to the list for handling when an event fires. Code examples are included for all topics.