Deprecated: Constant E_STRICT is deprecated in /home/pastorz/old-espace-client/vendor/symfony/error-handler/ErrorHandler.php on line 58

Deprecated: Constant E_STRICT is deprecated in /home/pastorz/old-espace-client/vendor/symfony/error-handler/ErrorHandler.php on line 76
Symfony Profiler

vendor/symfony/http-kernel/DataCollector/TimeDataCollector.php line 30

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <fabien@symfony.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Symfony\Component\HttpKernel\DataCollector;
  11. use Symfony\Component\HttpFoundation\Request;
  12. use Symfony\Component\HttpFoundation\Response;
  13. use Symfony\Component\HttpKernel\KernelInterface;
  14. use Symfony\Component\Stopwatch\Stopwatch;
  15. use Symfony\Component\Stopwatch\StopwatchEvent;
  16. /**
  17.  * @author Fabien Potencier <fabien@symfony.com>
  18.  *
  19.  * @final
  20.  */
  21. class TimeDataCollector extends DataCollector implements LateDataCollectorInterface
  22. {
  23.     private $kernel;
  24.     private $stopwatch;
  25.     public function __construct(KernelInterface $kernel nullStopwatch $stopwatch null)
  26.     {
  27.         $this->kernel $kernel;
  28.         $this->stopwatch $stopwatch;
  29.         $this->data = ['events' => [], 'stopwatch_installed' => false'start_time' => 0];
  30.     }
  31.     /**
  32.      * {@inheritdoc}
  33.      */
  34.     public function collect(Request $requestResponse $response\Throwable $exception null)
  35.     {
  36.         if (null !== $this->kernel) {
  37.             $startTime $this->kernel->getStartTime();
  38.         } else {
  39.             $startTime $request->server->get('REQUEST_TIME_FLOAT');
  40.         }
  41.         $this->data = [
  42.             'token' => $request->attributes->get('_stopwatch_token'),
  43.             'start_time' => $startTime 1000,
  44.             'events' => [],
  45.             'stopwatch_installed' => class_exists(Stopwatch::class, false),
  46.         ];
  47.     }
  48.     /**
  49.      * {@inheritdoc}
  50.      */
  51.     public function reset()
  52.     {
  53.         $this->data = ['events' => [], 'stopwatch_installed' => false'start_time' => 0];
  54.         if (null !== $this->stopwatch) {
  55.             $this->stopwatch->reset();
  56.         }
  57.     }
  58.     /**
  59.      * {@inheritdoc}
  60.      */
  61.     public function lateCollect()
  62.     {
  63.         if (null !== $this->stopwatch && isset($this->data['token'])) {
  64.             $this->setEvents($this->stopwatch->getSectionEvents($this->data['token']));
  65.         }
  66.         unset($this->data['token']);
  67.     }
  68.     /**
  69.      * @param StopwatchEvent[] $events The request events
  70.      */
  71.     public function setEvents(array $events)
  72.     {
  73.         foreach ($events as $event) {
  74.             $event->ensureStopped();
  75.         }
  76.         $this->data['events'] = $events;
  77.     }
  78.     /**
  79.      * @return StopwatchEvent[]
  80.      */
  81.     public function getEvents(): array
  82.     {
  83.         return $this->data['events'];
  84.     }
  85.     /**
  86.      * Gets the request elapsed time.
  87.      */
  88.     public function getDuration(): float
  89.     {
  90.         if (!isset($this->data['events']['__section__'])) {
  91.             return 0;
  92.         }
  93.         $lastEvent $this->data['events']['__section__'];
  94.         return $lastEvent->getOrigin() + $lastEvent->getDuration() - $this->getStartTime();
  95.     }
  96.     /**
  97.      * Gets the initialization time.
  98.      *
  99.      * This is the time spent until the beginning of the request handling.
  100.      */
  101.     public function getInitTime(): float
  102.     {
  103.         if (!isset($this->data['events']['__section__'])) {
  104.             return 0;
  105.         }
  106.         return $this->data['events']['__section__']->getOrigin() - $this->getStartTime();
  107.     }
  108.     public function getStartTime(): float
  109.     {
  110.         return $this->data['start_time'];
  111.     }
  112.     public function isStopwatchInstalled(): bool
  113.     {
  114.         return $this->data['stopwatch_installed'];
  115.     }
  116.     /**
  117.      * {@inheritdoc}
  118.      */
  119.     public function getName(): string
  120.     {
  121.         return 'time';
  122.     }
  123. }