Chris@0: Chris@0: * Chris@0: * For the full copyright and license information, please view the LICENSE Chris@0: * file that was distributed with this source code. Chris@0: */ Chris@0: Chris@0: namespace Symfony\Component\HttpKernel\DataCollector; Chris@0: Chris@17: use Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcherInterface; Chris@17: use Symfony\Component\EventDispatcher\EventDispatcherInterface; Chris@0: use Symfony\Component\HttpFoundation\Request; Chris@0: use Symfony\Component\HttpFoundation\Response; Chris@0: Chris@0: /** Chris@0: * EventDataCollector. Chris@0: * Chris@0: * @author Fabien Potencier Chris@0: */ Chris@0: class EventDataCollector extends DataCollector implements LateDataCollectorInterface Chris@0: { Chris@0: protected $dispatcher; Chris@0: Chris@0: public function __construct(EventDispatcherInterface $dispatcher = null) Chris@0: { Chris@14: if ($dispatcher instanceof TraceableEventDispatcherInterface && !method_exists($dispatcher, 'reset')) { Chris@14: @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); Chris@14: } Chris@0: $this->dispatcher = $dispatcher; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function collect(Request $request, Response $response, \Exception $exception = null) Chris@0: { Chris@17: $this->data = [ Chris@17: 'called_listeners' => [], Chris@17: 'not_called_listeners' => [], Chris@17: ]; Chris@0: } Chris@0: Chris@14: public function reset() Chris@14: { Chris@17: $this->data = []; Chris@14: Chris@14: if ($this->dispatcher instanceof TraceableEventDispatcherInterface) { Chris@14: if (!method_exists($this->dispatcher, 'reset')) { Chris@14: return; // @deprecated Chris@14: } Chris@14: Chris@14: $this->dispatcher->reset(); Chris@14: } Chris@14: } Chris@14: Chris@0: public function lateCollect() Chris@0: { Chris@0: if ($this->dispatcher instanceof TraceableEventDispatcherInterface) { Chris@0: $this->setCalledListeners($this->dispatcher->getCalledListeners()); Chris@0: $this->setNotCalledListeners($this->dispatcher->getNotCalledListeners()); Chris@0: } Chris@14: $this->data = $this->cloneVar($this->data); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Sets the called listeners. Chris@0: * Chris@0: * @param array $listeners An array of called listeners Chris@0: * Chris@0: * @see TraceableEventDispatcherInterface Chris@0: */ Chris@0: public function setCalledListeners(array $listeners) Chris@0: { Chris@0: $this->data['called_listeners'] = $listeners; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Gets the called listeners. Chris@0: * Chris@0: * @return array An array of called listeners Chris@0: * Chris@0: * @see TraceableEventDispatcherInterface Chris@0: */ Chris@0: public function getCalledListeners() Chris@0: { Chris@0: return $this->data['called_listeners']; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Sets the not called listeners. Chris@0: * Chris@0: * @param array $listeners An array of not called listeners Chris@0: * Chris@0: * @see TraceableEventDispatcherInterface Chris@0: */ Chris@0: public function setNotCalledListeners(array $listeners) Chris@0: { Chris@0: $this->data['not_called_listeners'] = $listeners; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Gets the not called listeners. Chris@0: * Chris@0: * @return array An array of not called listeners Chris@0: * Chris@0: * @see TraceableEventDispatcherInterface Chris@0: */ Chris@0: public function getNotCalledListeners() Chris@0: { Chris@0: return $this->data['not_called_listeners']; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function getName() Chris@0: { Chris@0: return 'events'; Chris@0: } Chris@0: }