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\HttpKernel\Profiler\Profiler;
16 use Symfony\Component\HttpKernel\KernelEvents;
17 use Symfony\Component\EventDispatcher\Event;
20 * Collects some data about event listeners.
22 * This event dispatcher delegates the dispatching to another one.
24 * @author Fabien Potencier <fabien@symfony.com>
26 class TraceableEventDispatcher extends BaseTraceableEventDispatcher
31 * The traceable event dispatcher does not use the profiler anymore.
32 * The job is now done directly by the Profiler listener and the
33 * data collectors themselves.
35 * @param Profiler|null $profiler A Profiler instance
37 * @deprecated since version 2.4, to be removed in 3.0.
39 public function setProfiler(Profiler $profiler = null)
41 @trigger_error('The '.__METHOD__.' method is deprecated since version 2.4 and will be removed in 3.0.', E_USER_DEPRECATED);
47 protected function preDispatch($eventName, Event $event)
50 case KernelEvents::REQUEST:
51 $this->stopwatch->openSection();
53 case KernelEvents::VIEW:
54 case KernelEvents::RESPONSE:
55 // stop only if a controller has been executed
56 if ($this->stopwatch->isStarted('controller')) {
57 $this->stopwatch->stop('controller');
60 case KernelEvents::TERMINATE:
61 $token = $event->getResponse()->headers->get('X-Debug-Token');
62 // There is a very special case when using built-in AppCache class as kernel wrapper, in the case
63 // of an ESI request leading to a `stale` response [B] inside a `fresh` cached response [A].
64 // In this case, `$token` contains the [B] debug token, but the open `stopwatch` section ID
65 // is equal to the [A] debug token. Trying to reopen section with the [B] token throws an exception
66 // which must be caught.
68 $this->stopwatch->openSection($token);
69 } catch (\LogicException $e) {
78 protected function postDispatch($eventName, Event $event)
81 case KernelEvents::CONTROLLER:
82 $this->stopwatch->start('controller', 'section');
84 case KernelEvents::RESPONSE:
85 $token = $event->getResponse()->headers->get('X-Debug-Token');
86 $this->stopwatch->stopSection($token);
88 case KernelEvents::TERMINATE:
89 // In the special case described in the `preDispatch` method above, the `$token` section
90 // does not exist, then closing it throws an exception which must be caught.
91 $token = $event->getResponse()->headers->get('X-Debug-Token');
93 $this->stopwatch->stopSection($token);
94 } catch (\LogicException $e) {