Final Class Yiisoft\Yii\Debug\Collector\HttpClientCollector
| Inheritance | Yiisoft\Yii\Debug\Collector\HttpClientCollector |
|---|---|
| Implements | Yiisoft\Yii\Debug\Collector\SummaryCollectorInterface |
| Uses Traits | Yiisoft\Yii\Debug\Collector\CollectorTrait |
Psalm Types
| Name | Value |
|---|---|
| RequestEntry | array{startTime: float, endTime: float, totalTime: float, method: string, uri: string, headers: string[][], line: string, responseRaw?: string, responseStatus?: integer} |
Public Methods
Method Details
| public mixed __construct ( Yiisoft\Yii\Debug\Collector\TimelineCollector $timelineCollector ) | ||
| $timelineCollector | Yiisoft\Yii\Debug\Collector\TimelineCollector | |
public function __construct(
private readonly TimelineCollector $timelineCollector
) {
}
| public void collect ( \Psr\Http\Message\RequestInterface $request, float $startTime, string $line, string $uniqueId ) | ||
| $request | \Psr\Http\Message\RequestInterface | |
| $startTime | float | |
| $line | string | |
| $uniqueId | string | |
public function collect(RequestInterface $request, float $startTime, string $line, string $uniqueId): void
{
if (!$this->isActive()) {
return;
}
$this->requests[$uniqueId][] = [
'startTime' => $startTime,
'endTime' => $startTime,
'totalTime' => 0.0,
'method' => $request->getMethod(),
'uri' => (string) $request->getUri(),
'headers' => $request->getHeaders(),
'line' => $line,
];
$this->timelineCollector->collect($this, $uniqueId);
}
| public void collectTotalTime ( \Psr\Http\Message\ResponseInterface|null $response, float $endTime, string|null $uniqueId ) | ||
| $response | \Psr\Http\Message\ResponseInterface|null | |
| $endTime | float | |
| $uniqueId | string|null | |
public function collectTotalTime(?ResponseInterface $response, float $endTime, ?string $uniqueId): void
{
if (!$this->isActive()) {
return;
}
if (!isset($this->requests[$uniqueId])) {
return;
}
/** @psalm-suppress UnsupportedReferenceUsage */
$entry = &$this->requests[$uniqueId][count($this->requests[$uniqueId]) - 1];
if ($response instanceof ResponseInterface) {
$entry['responseRaw'] = Message::toString($response);
$entry['responseStatus'] = $response->getStatusCode();
Message::rewindBody($response);
}
$entry['endTime'] = $endTime;
$entry['totalTime'] = $entry['endTime'] - $entry['startTime'];
}
| public array getCollected ( ) |
public function getCollected(): array
{
if (!$this->isActive()) {
return [];
}
return array_merge(...array_values($this->requests));
}
| public array getSummary ( ) |
public function getSummary(): array
{
if (!$this->isActive()) {
return [];
}
return [
'count' => array_sum(array_map(static fn (array $requests) => count($requests), $this->requests)),
'totalTime' => array_sum(
array_merge(
...array_map(
static fn (array $entry) => array_column($entry, 'totalTime'),
array_values($this->requests)
)
)
),
];
}
| public void shutdown ( ) |
public function shutdown(): void
{
$this->reset();
$this->isActive = false;
}
Signup or Login in order to comment.