merged branch lmcd/kernelevents-constants (PR #6499)

This PR was merged into the master branch.

Commits
-------

d5948f1 Use KernelEvents constants in TraceableEventDispatcher

Discussion
----------

[HttpKernel] Use KernelEvents constants in TraceableEventDispatcher

Can't see any reason why we're not using constants here.
This commit is contained in:
Fabien Potencier 2012-12-29 00:07:33 +01:00
commit 3778bf916e

View File

@ -12,6 +12,7 @@
namespace Symfony\Component\HttpKernel\Debug; namespace Symfony\Component\HttpKernel\Debug;
use Symfony\Component\Stopwatch\Stopwatch; use Symfony\Component\Stopwatch\Stopwatch;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpKernel\Log\LoggerInterface; use Symfony\Component\HttpKernel\Log\LoggerInterface;
use Symfony\Component\HttpKernel\Profiler\Profile; use Symfony\Component\HttpKernel\Profiler\Profile;
use Symfony\Component\HttpKernel\Profiler\Profiler; use Symfony\Component\HttpKernel\Profiler\Profiler;
@ -374,18 +375,18 @@ class TraceableEventDispatcher implements EventDispatcherInterface, TraceableEve
} }
switch ($eventName) { switch ($eventName) {
case 'kernel.request': case KernelEvents::REQUEST:
$this->stopwatch->openSection(); $this->stopwatch->openSection();
break; break;
case 'kernel.view': case KernelEvents::VIEW:
case 'kernel.response': case KernelEvents::RESPONSE:
// stop only if a controller has been executed // stop only if a controller has been executed
try { try {
$this->stopwatch->stop('controller'); $this->stopwatch->stop('controller');
} catch (\LogicException $e) { } catch (\LogicException $e) {
} }
break; break;
case 'kernel.terminate': case KernelEvents::TERMINATE:
$token = $event->getResponse()->headers->get('X-Debug-Token'); $token = $event->getResponse()->headers->get('X-Debug-Token');
$this->stopwatch->openSection($token); $this->stopwatch->openSection($token);
break; break;
@ -395,10 +396,10 @@ class TraceableEventDispatcher implements EventDispatcherInterface, TraceableEve
private function postDispatch($eventName, Event $event) private function postDispatch($eventName, Event $event)
{ {
switch ($eventName) { switch ($eventName) {
case 'kernel.controller': case KernelEvents::CONTROLLER:
$this->stopwatch->start('controller', 'section'); $this->stopwatch->start('controller', 'section');
break; break;
case 'kernel.response': case KernelEvents::RESPONSE:
$token = $event->getResponse()->headers->get('X-Debug-Token'); $token = $event->getResponse()->headers->get('X-Debug-Token');
$this->stopwatch->stopSection($token); $this->stopwatch->stopSection($token);
if (HttpKernelInterface::MASTER_REQUEST === $event->getRequestType()) { if (HttpKernelInterface::MASTER_REQUEST === $event->getRequestType()) {
@ -407,7 +408,7 @@ class TraceableEventDispatcher implements EventDispatcherInterface, TraceableEve
$this->updateProfiles($token, true); $this->updateProfiles($token, true);
} }
break; break;
case 'kernel.terminate': case KernelEvents::TERMINATE:
$token = $event->getResponse()->headers->get('X-Debug-Token'); $token = $event->getResponse()->headers->get('X-Debug-Token');
$this->stopwatch->stopSection($token); $this->stopwatch->stopSection($token);
// The children profiles have been updated by the previous 'kernel.response' // The children profiles have been updated by the previous 'kernel.response'