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\Debug;
14 use Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcher as BaseTraceableEventDispatcher;
15 use Symfony\Component\EventDispatcher\Event;
16 use Symfony\Component\HttpKernel\KernelEvents;
19 * Collects some data about event listeners.
21 * This event dispatcher delegates the dispatching to another one.
23 * @author Fabien Potencier <fabien@symfony.com>
25 class TraceableEventDispatcher extends BaseTraceableEventDispatcher
30 protected function preDispatch($eventName, Event $event)
33 case KernelEvents::REQUEST:
34 $this->stopwatch->openSection();
36 case KernelEvents::VIEW:
37 case KernelEvents::RESPONSE:
38 // stop only if a controller has been executed
39 if ($this->stopwatch->isStarted('controller')) {
40 $this->stopwatch->stop('controller');
43 case KernelEvents::TERMINATE:
44 $token = $event->getResponse()->headers->get('X-Debug-Token');
45 // There is a very special case when using built-in AppCache class as kernel wrapper, in the case
46 // of an ESI request leading to a `stale` response [B] inside a `fresh` cached response [A].
47 // In this case, `$token` contains the [B] debug token, but the open `stopwatch` section ID
48 // is equal to the [A] debug token. Trying to reopen section with the [B] token throws an exception
49 // which must be caught.
51 $this->stopwatch->openSection($token);
52 } catch (\LogicException $e) {
61 protected function postDispatch($eventName, Event $event)
64 case KernelEvents::CONTROLLER_ARGUMENTS:
65 $this->stopwatch->start('controller', 'section');
67 case KernelEvents::RESPONSE:
68 $token = $event->getResponse()->headers->get('X-Debug-Token');
69 $this->stopwatch->stopSection($token);
71 case KernelEvents::TERMINATE:
72 // In the special case described in the `preDispatch` method above, the `$token` section
73 // does not exist, then closing it throws an exception which must be caught.
74 $token = $event->getResponse()->headers->get('X-Debug-Token');
76 $this->stopwatch->stopSection($token);
77 } catch (\LogicException $e) {