12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- <?php
- namespace Symfony\Component\HttpKernel\Debug;
- use Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcher as BaseTraceableEventDispatcher;
- use Symfony\Component\HttpKernel\KernelEvents;
- class TraceableEventDispatcher extends BaseTraceableEventDispatcher
- {
-
- protected function beforeDispatch(string $eventName, object $event)
- {
- switch ($eventName) {
- case KernelEvents::REQUEST:
- $event->getRequest()->attributes->set('_stopwatch_token', substr(hash('sha256', uniqid(mt_rand(), true)), 0, 6));
- $this->stopwatch->openSection();
- break;
- case KernelEvents::VIEW:
- case KernelEvents::RESPONSE:
-
- if ($this->stopwatch->isStarted('controller')) {
- $this->stopwatch->stop('controller');
- }
- break;
- case KernelEvents::TERMINATE:
- $sectionId = $event->getRequest()->attributes->get('_stopwatch_token');
- if (null === $sectionId) {
- break;
- }
-
-
-
-
-
- try {
- $this->stopwatch->openSection($sectionId);
- } catch (\LogicException $e) {
- }
- break;
- }
- }
-
- protected function afterDispatch(string $eventName, object $event)
- {
- switch ($eventName) {
- case KernelEvents::CONTROLLER_ARGUMENTS:
- $this->stopwatch->start('controller', 'section');
- break;
- case KernelEvents::RESPONSE:
- $sectionId = $event->getRequest()->attributes->get('_stopwatch_token');
- if (null === $sectionId) {
- break;
- }
- $this->stopwatch->stopSection($sectionId);
- break;
- case KernelEvents::TERMINATE:
-
-
- $sectionId = $event->getRequest()->attributes->get('_stopwatch_token');
- if (null === $sectionId) {
- break;
- }
- try {
- $this->stopwatch->stopSection($sectionId);
- } catch (\LogicException $e) {
- }
- break;
- }
- }
- }
|