Symfony 5.3 is backed by JoliCode. The EventDispatcher component provides tools that allow your application components to communicate with each other by dispatching events and listening to them. Object-oriented code has gone a long way to ensuring code extensibility.
Besides, An Symfony\Contracts\EventDispatcher\Event instance is also created and passed to all of the listeners. As you’ll see later, the Event object itself often contains data about the event being dispatched. The unique event name can be any string, but optionally follows a few naming conventions: In respect to this, For the kernel.exception event, it is Symfony\Component\HttpKernel\Event\ExceptionEvent . Check out the Symfony events reference to see what type of object each event provides. Also, End names with a verb that indicates what action has been taken (e.g. order.placed ). When the dispatcher notifies listeners, it passes an actual Event object to those listeners. The base Event class contains a method for stopping event propagation, but not much else. In fact, That was a simple example, as we only wanted to set up a listener for a single event. On the other hand, if you want to set up listeners for multiple events or you want to logically group event handling logic in a single class, you should consider using event subscribers because they allow you to keep everything in one place.
1 Similar Question Found
How does the eventdispatcher hook up to the dispatcher?
When an event is dispatched via the dispatcher, it notifies all listeners registered with that event: To take advantage of an existing event, you need to connect a listener to the dispatcher so that it can be notified when the event is dispatched. A call to the dispatcher’s addListener () method associates any valid PHP callable to an event:
This website uses cookies or similar technologies, to enhance your browsing experience and provide personalized recommendations. By continuing to use our website, you agree to our Privacy Policy