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

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\TraceableEventDispatcherInterface;
  12. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  13. use Symfony\Component\HttpFoundation\Request;
  14. use Symfony\Component\HttpFoundation\Response;
  15. /**
  16.  * EventDataCollector.
  17.  *
  18.  * @author Fabien Potencier <fabien@symfony.com>
  19.  */
  20. class EventDataCollector extends DataCollector implements LateDataCollectorInterface
  21. {
  22.     protected $dispatcher;
  23.     public function __construct(EventDispatcherInterface $dispatcher null)
  24.     {
  25.         if ($dispatcher instanceof TraceableEventDispatcherInterface && !method_exists($dispatcher'reset')) {
  26.             @trigger_error(sprintf('Implementing "%s" without the "reset()" method is deprecated since Symfony 3.4 and will be unsupported in 4.0 for class "%s".'TraceableEventDispatcherInterface::class, \get_class($dispatcher)), \E_USER_DEPRECATED);
  27.         }
  28.         $this->dispatcher $dispatcher;
  29.     }
  30.     /**
  31.      * {@inheritdoc}
  32.      */
  33.     public function collect(Request $requestResponse $response, \Exception $exception null)
  34.     {
  35.         $this->data = [
  36.             'called_listeners' => [],
  37.             'not_called_listeners' => [],
  38.         ];
  39.     }
  40.     public function reset()
  41.     {
  42.         $this->data = [];
  43.         if ($this->dispatcher instanceof TraceableEventDispatcherInterface) {
  44.             if (!method_exists($this->dispatcher'reset')) {
  45.                 return; // @deprecated
  46.             }
  47.             $this->dispatcher->reset();
  48.         }
  49.     }
  50.     public function lateCollect()
  51.     {
  52.         if ($this->dispatcher instanceof TraceableEventDispatcherInterface) {
  53.             $this->setCalledListeners($this->dispatcher->getCalledListeners());
  54.             $this->setNotCalledListeners($this->dispatcher->getNotCalledListeners());
  55.         }
  56.         $this->data $this->cloneVar($this->data);
  57.     }
  58.     /**
  59.      * Sets the called listeners.
  60.      *
  61.      * @param array $listeners An array of called listeners
  62.      *
  63.      * @see TraceableEventDispatcherInterface
  64.      */
  65.     public function setCalledListeners(array $listeners)
  66.     {
  67.         $this->data['called_listeners'] = $listeners;
  68.     }
  69.     /**
  70.      * Gets the called listeners.
  71.      *
  72.      * @return array An array of called listeners
  73.      *
  74.      * @see TraceableEventDispatcherInterface
  75.      */
  76.     public function getCalledListeners()
  77.     {
  78.         return $this->data['called_listeners'];
  79.     }
  80.     /**
  81.      * Sets the not called listeners.
  82.      *
  83.      * @param array $listeners An array of not called listeners
  84.      *
  85.      * @see TraceableEventDispatcherInterface
  86.      */
  87.     public function setNotCalledListeners(array $listeners)
  88.     {
  89.         $this->data['not_called_listeners'] = $listeners;
  90.     }
  91.     /**
  92.      * Gets the not called listeners.
  93.      *
  94.      * @return array An array of not called listeners
  95.      *
  96.      * @see TraceableEventDispatcherInterface
  97.      */
  98.     public function getNotCalledListeners()
  99.     {
  100.         return $this->data['not_called_listeners'];
  101.     }
  102.     /**
  103.      * {@inheritdoc}
  104.      */
  105.     public function getName()
  106.     {
  107.         return 'events';
  108.     }
  109. }