3 namespace Drupal\webprofiler;
5 use Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcher as BaseTraceableEventDispatcher;
6 use Symfony\Component\HttpKernel\KernelEvents;
7 use Symfony\Component\EventDispatcher\Event;
10 * Class TraceableEventDispatcher
12 class TraceableEventDispatcher extends BaseTraceableEventDispatcher {
17 protected function preDispatch($eventName, Event $event) {
19 case KernelEvents::VIEW:
20 case KernelEvents::RESPONSE:
21 // stop only if a controller has been executed
22 if ($this->stopwatch->isStarted('controller')) {
23 $this->stopwatch->stop('controller');
32 protected function postDispatch($eventName, Event $event) {
34 case KernelEvents::CONTROLLER:
35 $this->stopwatch->start('controller', 'section');
37 case KernelEvents::RESPONSE:
38 $token = $event->getResponse()->headers->get('X-Debug-Token');
40 $this->stopwatch->stopSection($token);
41 } catch (\LogicException $e) {
44 case KernelEvents::TERMINATE:
45 // In the special case described in the `preDispatch` method above, the `$token` section
46 // does not exist, then closing it throws an exception which must be caught.
47 $token = $event->getResponse()->headers->get('X-Debug-Token');
49 $this->stopwatch->stopSection($token);
50 } catch (\LogicException $e) {
59 public function getListenerPriority($eventName, $listener) {
60 if (!isset($this->listeners[$eventName])) {
63 foreach ($this->listeners[$eventName] as $priority => $listeners) {
64 if (FALSE !== ($key = array_search($listener, $listeners, TRUE))) {