title: Using the Symfony 2 Event Dispatcher
body: <p>How, if at all, should a Symfony 2 bundle developer use the event dispatcher(s) that ship with a stock Symfony 2 system?</p>
  
  <p>I've been digging around in the source for Symfony's event dispatcher, and some of what I've seen has me a little confused as to how I, a third party bundle creator, should use the event dispatcher that ships with Symfony.</p>
  
  <p>Specifically, I noticed that a stock Symfony system has <strong>two</strong> event dispatcher services.  The <code>event_dispatcher</code> and the <code>debug.event_dispatcher</code>. Which service the <strong>HttpKernel</strong> uses is dependent on environment, and driven by the generated dev or prod container file.</p>
  
  <pre><code>//dev kernel instantiation uses `debug.event_dispatcher` service
  new \Symfony\Component\HttpKernel\DependencyInjection\ContainerAwareHttpKernel(
              $this-&gt;get('debug.event_dispatcher'), 
              $this, 
              $this-&gt;get('debug.controller_resolver')
          );
  
  //prod kernel instantiation uses `event_dispatcher` service         
  new \Symfony\Component\HttpKernel\DependencyInjection\ContainerAwareHttpKernel(
              $this-&gt;get('event_dispatcher'), 
              $this, 
              new \Symfony\Bundle\FrameworkBundle\Controller\ControllerResolver($this, $this-&gt;get('controller_name_converter'), $this-&gt;get('monolog.logger.request', ContainerInterface::NULL_ON_INVALID_REFERENCE)));
  </code></pre>
  
  <p>So far this all makes sense — as it's the <code>debug.event_dispatcher</code> that implements functionality in the web profile's event's tab, including the ability to see which listeners were called, and which listeners were not called.  </p>
  
  <p>However, I noticed most (if not all) third party bundles use a hard coded <code>event_dispatcher</code> service call.  For example, the <a href="https://github.com/schmittjoh/JMSJobQueueBundle/blob/master/Command/RunCommand.php#L71">JMS/JobQueueBundle</a> uses the following</p>
  
  <pre><code>$this-&gt;dispatcher = $this-&gt;getContainer()-&gt;get('event_dispatcher');
  </code></pre>
  
  <p>Events dispatched like this fire correctly, <strong>but</strong> the <code>debug.event_dispatcher</code> doesn't know about them, which means the Symfony web profiler will incorrectly list a called listener as uncalled.  Additionally, it's not clear how a bundle author could avoid this, as they don't have the advantage of generating a container file <strong>and</strong> the HTTP Kernel object doesn't expose an accessor for the protected dispatcher object. </p>
  
  <p>So, is this a bug in Symfony?</p>
  
  <p>Or is the <code>event_dispatcher</code> service only intended for Kernel events, meaning all those bundle authors are misusing it?</p>
  
  <p>Or (the most likely candidate), is it something else I'm missing or haven't considered? </p>