4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\HttpKernel\DataCollector;
14 use Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcherInterface;
15 use Symfony\Component\EventDispatcher\EventDispatcherInterface;
16 use Symfony\Component\HttpFoundation\Request;
17 use Symfony\Component\HttpFoundation\Response;
22 * @author Fabien Potencier <fabien@symfony.com>
24 class EventDataCollector extends DataCollector implements LateDataCollectorInterface
26 protected $dispatcher;
28 public function __construct(EventDispatcherInterface $dispatcher = null)
30 if ($dispatcher instanceof TraceableEventDispatcherInterface && !method_exists($dispatcher, 'reset')) {
31 @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);
33 $this->dispatcher = $dispatcher;
39 public function collect(Request $request, Response $response, \Exception $exception = null)
42 'called_listeners' => array(),
43 'not_called_listeners' => array(),
47 public function reset()
49 $this->data = array();
51 if ($this->dispatcher instanceof TraceableEventDispatcherInterface) {
52 if (!method_exists($this->dispatcher, 'reset')) {
53 return; // @deprecated
56 $this->dispatcher->reset();
60 public function lateCollect()
62 if ($this->dispatcher instanceof TraceableEventDispatcherInterface) {
63 $this->setCalledListeners($this->dispatcher->getCalledListeners());
64 $this->setNotCalledListeners($this->dispatcher->getNotCalledListeners());
66 $this->data = $this->cloneVar($this->data);
70 * Sets the called listeners.
72 * @param array $listeners An array of called listeners
74 * @see TraceableEventDispatcherInterface
76 public function setCalledListeners(array $listeners)
78 $this->data['called_listeners'] = $listeners;
82 * Gets the called listeners.
84 * @return array An array of called listeners
86 * @see TraceableEventDispatcherInterface
88 public function getCalledListeners()
90 return $this->data['called_listeners'];
94 * Sets the not called listeners.
96 * @param array $listeners An array of not called listeners
98 * @see TraceableEventDispatcherInterface
100 public function setNotCalledListeners(array $listeners)
102 $this->data['not_called_listeners'] = $listeners;
106 * Gets the not called listeners.
108 * @return array An array of not called listeners
110 * @see TraceableEventDispatcherInterface
112 public function getNotCalledListeners()
114 return $this->data['not_called_listeners'];
120 public function getName()