<?php
namespace App\EventSubscriber;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
use Symfony\Component\HttpFoundation\StreamedResponse;
class TimeLoadSubscriber implements EventSubscriberInterface
{
public function onResponseEvent(ResponseEvent $event)
{
if(!$event->isMasterRequest()){
return;
}
$response = $event->getResponse();
if($response instanceof StreamedResponse){
return $response;
}
global $start_apunts;
$time = explode(' ', microtime());
$time = $time[1] + $time[0];
$finish = $time;
$total_time = round(($finish - $start_apunts), 4);
$response->setContent(
str_replace('1754121319.1793 s', $total_time . ' s', $response->getContent())
);
return $response;
}
public static function getSubscribedEvents()
{
return [
ResponseEvent::class => 'onResponseEvent',
];
}
}