Get Event Listeners Using Console Command in Symfony 7

Get Event Listeners Using Console Command in Symfony 7

The Symfony framework offers many pre-built commands tailored to simplify the debugging process for various aspects within an application. Event listeners play a crucial role in Symfony applications, allowing developers to respond to specific events triggered during the application's lifecycle. This tutorial demonstrates how to get event listeners using console command in Symfony 7.

Symfony provides the debug:event-dispatcher command, a handy tool for discovering and inspecting the various events and their associated listeners within the Symfony application. This command provides an overview of the events registered in the application, including details about the listeners attached to each event.

Execute the following command to display all events and their corresponding listeners:

php bin/console debug:event-dispatcher

You may want to focus on specific events. To obtain the registered listeners for a specific event, specify its name as follows:

php bin/console debug:event-dispatcher kernel.exception

Output example:

Registered Listeners for "kernel.exception" Event
=================================================

 ------- ---------------------------------------------------------------------------------- ----------
  Order   Callable                                                                           Priority
 ------- ---------------------------------------------------------------------------------- ----------
  #1      Symfony\Component\HttpKernel\EventListener\ErrorListener::logKernelException()     0
  #2      Symfony\Component\HttpKernel\EventListener\ProfilerListener::onKernelException()   0
  #3      Symfony\Component\HttpKernel\EventListener\RouterListener::onKernelException()     -64
  #4      Symfony\Component\HttpKernel\EventListener\ErrorListener::onKernelException()      -128
 ------- ---------------------------------------------------------------------------------- ----------

Leave a Comment

Cancel reply

Your email address will not be published.