src/EventSubscriber/TimeLoadSubscriber.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber;
  3. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  4. use Symfony\Component\HttpKernel\Event\ResponseEvent;
  5. use Symfony\Component\HttpFoundation\StreamedResponse;
  6. class TimeLoadSubscriber implements EventSubscriberInterface
  7. {
  8.     public function onResponseEvent(ResponseEvent $event)
  9.     {
  10.         if(!$event->isMasterRequest()){
  11.             return;
  12.         }
  13.         $response $event->getResponse();
  14.         if($response instanceof StreamedResponse){
  15.             return $response;
  16.         }
  17.         global $start_apunts
  18.         $time explode(' 'microtime());
  19.         $time $time[1] + $time[0];
  20.         $finish $time;
  21.         $total_time round(($finish $start_apunts), 4);
  22.         $response->setContent(
  23.             str_replace('1754135057.3377 s'$total_time ' s'$response->getContent())
  24.         );
  25.         return $response;
  26.     }
  27.     public static function getSubscribedEvents()
  28.     {
  29.         return [
  30.             ResponseEvent::class => 'onResponseEvent',
  31.         ];
  32.     }
  33. }