class TimeDataCollector
@author Fabien Potencier <fabien@symfony.com>
@final
Hierarchy
- class \Symfony\Component\HttpKernel\DataCollector\DataCollector implements \Symfony\Component\HttpKernel\DataCollector\DataCollectorInterface
- class \Symfony\Component\HttpKernel\DataCollector\TimeDataCollector extends \Symfony\Component\HttpKernel\DataCollector\DataCollector implements \Symfony\Component\HttpKernel\DataCollector\LateDataCollectorInterface
Expanded class hierarchy of TimeDataCollector
File
-
vendor/
symfony/ http-kernel/ DataCollector/ TimeDataCollector.php, line 25
Namespace
Symfony\Component\HttpKernel\DataCollectorView source
class TimeDataCollector extends DataCollector implements LateDataCollectorInterface {
public function __construct(?KernelInterface $kernel = null, ?Stopwatch $stopwatch = null) {
$this->data = [
'events' => [],
'stopwatch_installed' => false,
'start_time' => 0,
];
}
public function collect(Request $request, Response $response, ?\Throwable $exception = null) : void {
if (null !== $this->kernel) {
$startTime = $this->kernel
->getStartTime();
}
else {
$startTime = $request->server
->get('REQUEST_TIME_FLOAT');
}
$this->data = [
'token' => $request->attributes
->get('_stopwatch_token'),
'start_time' => $startTime * 1000,
'events' => [],
'stopwatch_installed' => class_exists(Stopwatch::class, false),
];
}
public function reset() : void {
$this->data = [
'events' => [],
'stopwatch_installed' => false,
'start_time' => 0,
];
$this->stopwatch?->reset();
}
public function lateCollect() : void {
if (null !== $this->stopwatch && isset($this->data['token'])) {
$this->setEvents($this->stopwatch
->getSectionEvents($this->data['token']));
}
unset($this->data['token']);
}
/**
* @param StopwatchEvent[] $events The request events
*/
public function setEvents(array $events) : void {
foreach ($events as $event) {
$event->ensureStopped();
}
$this->data['events'] = $events;
}
/**
* @return StopwatchEvent[]
*/
public function getEvents() : array {
return $this->data['events'];
}
/**
* Gets the request elapsed time.
*/
public function getDuration() : float {
if (!isset($this->data['events']['__section__'])) {
return 0;
}
$lastEvent = $this->data['events']['__section__'];
return $lastEvent->getOrigin() + $lastEvent->getDuration() - $this->getStartTime();
}
/**
* Gets the initialization time.
*
* This is the time spent until the beginning of the request handling.
*/
public function getInitTime() : float {
if (!isset($this->data['events']['__section__'])) {
return 0;
}
return $this->data['events']['__section__']
->getOrigin() - $this->getStartTime();
}
public function getStartTime() : float {
return $this->data['start_time'];
}
public function isStopwatchInstalled() : bool {
return $this->data['stopwatch_installed'];
}
public function getName() : string {
return 'time';
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title | Overrides |
---|---|---|---|---|---|
DataCollector::$cloner | private | property | |||
DataCollector::$data | protected | property | |||
DataCollector::cloneVar | protected | function | Converts the variable into a serializable Data instance. | ||
DataCollector::getCasters | protected | function | 1 | ||
DataCollector::serialize | final protected | function | @internal to prevent implementing \Serializable | ||
DataCollector::unserialize | final protected | function | @internal to prevent implementing \Serializable | ||
DataCollector::__sleep | public | function | 1 | ||
DataCollector::__wakeup | public | function | 1 | ||
TimeDataCollector::collect | public | function | Collects data for the given Request and Response. | Overrides DataCollectorInterface::collect | |
TimeDataCollector::getDuration | public | function | Gets the request elapsed time. | ||
TimeDataCollector::getEvents | public | function | |||
TimeDataCollector::getInitTime | public | function | Gets the initialization time. | ||
TimeDataCollector::getName | public | function | Returns the name of the collector. | Overrides DataCollectorInterface::getName | |
TimeDataCollector::getStartTime | public | function | |||
TimeDataCollector::isStopwatchInstalled | public | function | |||
TimeDataCollector::lateCollect | public | function | Collects data as late as possible. | Overrides LateDataCollectorInterface::lateCollect | |
TimeDataCollector::reset | public | function | Overrides DataCollector::reset | ||
TimeDataCollector::setEvents | public | function | |||
TimeDataCollector::__construct | public | function |