vendor/symfony/http-kernel/DataCollector/EventDataCollector.php line 65

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <fabien@symfony.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Symfony\Component\HttpKernel\DataCollector;
  11. use Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcher;
  12. use Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcherInterface;
  13. use Symfony\Component\HttpFoundation\Request;
  14. use Symfony\Component\HttpFoundation\RequestStack;
  15. use Symfony\Component\HttpFoundation\Response;
  16. use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
  17. use Symfony\Contracts\Service\ResetInterface;
  18. /**
  19.  * EventDataCollector.
  20.  *
  21.  * @author Fabien Potencier <fabien@symfony.com>
  22.  */
  23. class EventDataCollector extends DataCollector implements LateDataCollectorInterface
  24. {
  25.     protected $dispatcher;
  26.     private $requestStack;
  27.     private $currentRequest;
  28.     public function __construct(EventDispatcherInterface $dispatcher nullRequestStack $requestStack null)
  29.     {
  30.         $this->dispatcher $dispatcher;
  31.         $this->requestStack $requestStack;
  32.     }
  33.     /**
  34.      * {@inheritdoc}
  35.      */
  36.     public function collect(Request $requestResponse $response, \Exception $exception null)
  37.     {
  38.         $this->currentRequest $this->requestStack && $this->requestStack->getMasterRequest() !== $request $request null;
  39.         $this->data = [
  40.             'called_listeners' => [],
  41.             'not_called_listeners' => [],
  42.             'orphaned_events' => [],
  43.         ];
  44.     }
  45.     public function reset()
  46.     {
  47.         $this->data = [];
  48.         if ($this->dispatcher instanceof ResetInterface) {
  49.             $this->dispatcher->reset();
  50.         }
  51.     }
  52.     public function lateCollect()
  53.     {
  54.         if ($this->dispatcher instanceof TraceableEventDispatcherInterface) {
  55.             $this->setCalledListeners($this->dispatcher->getCalledListeners($this->currentRequest));
  56.             $this->setNotCalledListeners($this->dispatcher->getNotCalledListeners($this->currentRequest));
  57.         }
  58.         if ($this->dispatcher instanceof TraceableEventDispatcher) {
  59.             $this->setOrphanedEvents($this->dispatcher->getOrphanedEvents($this->currentRequest));
  60.         }
  61.         $this->data $this->cloneVar($this->data);
  62.     }
  63.     /**
  64.      * Sets the called listeners.
  65.      *
  66.      * @param array $listeners An array of called listeners
  67.      *
  68.      * @see TraceableEventDispatcher
  69.      */
  70.     public function setCalledListeners(array $listeners)
  71.     {
  72.         $this->data['called_listeners'] = $listeners;
  73.     }
  74.     /**
  75.      * Gets the called listeners.
  76.      *
  77.      * @return array An array of called listeners
  78.      *
  79.      * @see TraceableEventDispatcher
  80.      */
  81.     public function getCalledListeners()
  82.     {
  83.         return $this->data['called_listeners'];
  84.     }
  85.     /**
  86.      * Sets the not called listeners.
  87.      *
  88.      * @see TraceableEventDispatcher
  89.      */
  90.     public function setNotCalledListeners(array $listeners)
  91.     {
  92.         $this->data['not_called_listeners'] = $listeners;
  93.     }
  94.     /**
  95.      * Gets the not called listeners.
  96.      *
  97.      * @return array
  98.      *
  99.      * @see TraceableEventDispatcher
  100.      */
  101.     public function getNotCalledListeners()
  102.     {
  103.         return $this->data['not_called_listeners'];
  104.     }
  105.     /**
  106.      * Sets the orphaned events.
  107.      *
  108.      * @param array $events An array of orphaned events
  109.      *
  110.      * @see TraceableEventDispatcher
  111.      */
  112.     public function setOrphanedEvents(array $events)
  113.     {
  114.         $this->data['orphaned_events'] = $events;
  115.     }
  116.     /**
  117.      * Gets the orphaned events.
  118.      *
  119.      * @return array An array of orphaned events
  120.      *
  121.      * @see TraceableEventDispatcher
  122.      */
  123.     public function getOrphanedEvents()
  124.     {
  125.         return $this->data['orphaned_events'];
  126.     }
  127.     /**
  128.      * {@inheritdoc}
  129.      */
  130.     public function getName()
  131.     {
  132.         return 'events';
  133.     }
  134. }