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

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.  * @final since Symfony 4.4
  24.  */
  25. class EventDataCollector extends DataCollector implements LateDataCollectorInterface
  26. {
  27.     protected $dispatcher;
  28.     private $requestStack;
  29.     private $currentRequest;
  30.     public function __construct(EventDispatcherInterface $dispatcher nullRequestStack $requestStack null)
  31.     {
  32.         $this->dispatcher $dispatcher;
  33.         $this->requestStack $requestStack;
  34.     }
  35.     /**
  36.      * {@inheritdoc}
  37.      *
  38.      * @param \Throwable|null $exception
  39.      */
  40.     public function collect(Request $requestResponse $response/*, \Throwable $exception = null*/)
  41.     {
  42.         $this->currentRequest $this->requestStack && $this->requestStack->getMasterRequest() !== $request $request null;
  43.         $this->data = [
  44.             'called_listeners' => [],
  45.             'not_called_listeners' => [],
  46.             'orphaned_events' => [],
  47.         ];
  48.     }
  49.     public function reset()
  50.     {
  51.         $this->data = [];
  52.         if ($this->dispatcher instanceof ResetInterface) {
  53.             $this->dispatcher->reset();
  54.         }
  55.     }
  56.     public function lateCollect()
  57.     {
  58.         if ($this->dispatcher instanceof TraceableEventDispatcherInterface) {
  59.             $this->setCalledListeners($this->dispatcher->getCalledListeners($this->currentRequest));
  60.             $this->setNotCalledListeners($this->dispatcher->getNotCalledListeners($this->currentRequest));
  61.         }
  62.         if ($this->dispatcher instanceof TraceableEventDispatcher) {
  63.             $this->setOrphanedEvents($this->dispatcher->getOrphanedEvents($this->currentRequest));
  64.         }
  65.         $this->data $this->cloneVar($this->data);
  66.     }
  67.     /**
  68.      * Sets the called listeners.
  69.      *
  70.      * @param array $listeners An array of called listeners
  71.      *
  72.      * @see TraceableEventDispatcher
  73.      */
  74.     public function setCalledListeners(array $listeners)
  75.     {
  76.         $this->data['called_listeners'] = $listeners;
  77.     }
  78.     /**
  79.      * Gets the called listeners.
  80.      *
  81.      * @return array An array of called listeners
  82.      *
  83.      * @see TraceableEventDispatcher
  84.      */
  85.     public function getCalledListeners()
  86.     {
  87.         return $this->data['called_listeners'];
  88.     }
  89.     /**
  90.      * Sets the not called listeners.
  91.      *
  92.      * @see TraceableEventDispatcher
  93.      */
  94.     public function setNotCalledListeners(array $listeners)
  95.     {
  96.         $this->data['not_called_listeners'] = $listeners;
  97.     }
  98.     /**
  99.      * Gets the not called listeners.
  100.      *
  101.      * @return array
  102.      *
  103.      * @see TraceableEventDispatcher
  104.      */
  105.     public function getNotCalledListeners()
  106.     {
  107.         return $this->data['not_called_listeners'];
  108.     }
  109.     /**
  110.      * Sets the orphaned events.
  111.      *
  112.      * @param array $events An array of orphaned events
  113.      *
  114.      * @see TraceableEventDispatcher
  115.      */
  116.     public function setOrphanedEvents(array $events)
  117.     {
  118.         $this->data['orphaned_events'] = $events;
  119.     }
  120.     /**
  121.      * Gets the orphaned events.
  122.      *
  123.      * @return array An array of orphaned events
  124.      *
  125.      * @see TraceableEventDispatcher
  126.      */
  127.     public function getOrphanedEvents()
  128.     {
  129.         return $this->data['orphaned_events'];
  130.     }
  131.     /**
  132.      * {@inheritdoc}
  133.      */
  134.     public function getName()
  135.     {
  136.         return 'events';
  137.     }
  138. }