Answers.Body: <p>This maybe not best practice but something like this will list all the events and their handlers:</p>
  
  <pre><code> $kernel = \Civi::service('civi_api_kernel');                                
   $this-&gt;dispatcher = $kernel-&gt;getDispatcher();                             
   $listeners = $this-&gt;dispatcher-&gt;getListeners();                             
   foreach ($listeners as $event =&gt; $event_listeners) {                        
     echo "\n\n# $event\n";                                                    
     foreach ($event_listeners as $n =&gt; $listener) {                           
       echo "\n## Listener $n";
       $reflection = new \ReflectionClass($listener[0]);                       
       echo $reflection-&gt;getName() . "::" . ($listener[1]);
       echo "\nsource: " . $reflection-&gt;getFileName()                          
         . " lines: " . $reflection-&gt;getStartLine()
         . "-" . $reflection-&gt;getEndLine();
       // echo "\n Methods:" . json_encode(get_class_methods($listener[0]),JSON_PRETTY_PRINT);
     }   
   } 
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-02-27T23:01:25.627Z
Answers.Text: When I run this code I get "Cannot use object of type Closure as array".
Answers.UserDisplayName: Josh
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-03-17T01:57:59.023Z
Answers.LastActivityDate: 2017-03-17T01:57:59.023Z
Answers.UserDisplayName: ErichBSchulz
Body: <p>The API kernel uses a <a href="http://api.symfony.com/3.2/Symfony/Component/EventDispatcher.html" rel="nofollow noreferrer">symfony event system</a> at it's heart.</p>
  
  <p>How on earth do I find out where all those events are going?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-03-17T23:48:08.167Z
Comments.Text: http://stackoverflow.com/questions/18428656/getting-a-list-with-every-listeners-on-symfony2 related question
Comments.UserDisplayName: Chris Burgess
Tags: <php><symfony>
Title: How do I examine the symfony event handlers that are active?
ThreadText: # How do I examine the symfony event handlers that are active?
  
  (Asked by: username_0 on 2017-03-17)
  
  The API kernel uses a [symfony event system](http://api.symfony.com/3.2/Symfony/Component/EventDispatcher.html) at it's heart.
  
  How on earth do I find out where all those events are going?
  
  **Tags:** php, symfony
  
  > **Comments:**
  > **username_1**: http://stackoverflow.com/questions/18428656/getting-a-list-with-every-listeners-on-symfony2 related question  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2017-03-17. Score: 1
  
  This maybe not best practice but something like this will list all the events and their handlers:
  
  ```
   $kernel = \Civi::service('civi_api_kernel');                                
   $this->dispatcher = $kernel->getDispatcher();                             
   $listeners = $this->dispatcher->getListeners();                             
   foreach ($listeners as $event => $event_listeners) {                        
     echo "\n\n# $event\n";                                                    
     foreach ($event_listeners as $n => $listener) {                           
       echo "\n## Listener $n";
       $reflection = new \ReflectionClass($listener[0]);                       
       echo $reflection->getName() . "::" . ($listener[1]);
       echo "\nsource: " . $reflection->getFileName()                          
         . " lines: " . $reflection->getStartLine()
         . "-" . $reflection->getEndLine();
       // echo "\n Methods:" . json_encode(get_class_methods($listener[0]),JSON_PRETTY_PRINT);
     }   
   } 
  
  ```
  
  > **Comments:**
  > **username_2**: When I run this code I get "Cannot use object of type Closure as array".  
  
  ---
  
  