0 follower

Final Class Yiisoft\Yii\Debug\Collector\HttpClientCollector

InheritanceYiisoft\Yii\Debug\Collector\HttpClientCollector
ImplementsYiisoft\Yii\Debug\Collector\SummaryCollectorInterface
Uses TraitsYiisoft\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}

Method Details

Hide inherited methods

__construct() public method

public mixed __construct ( Yiisoft\Yii\Debug\Collector\TimelineCollector $timelineCollector )
$timelineCollector Yiisoft\Yii\Debug\Collector\TimelineCollector

                public function __construct(
    private readonly TimelineCollector $timelineCollector
) {
}

            
collect() public method

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);
}

            
collectTotalTime() public method

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'];
}

            
getCollected() public method

public array getCollected ( )

                public function getCollected(): array
{
    if (!$this->isActive()) {
        return [];
    }
    return array_merge(...array_values($this->requests));
}

            
getName() public method
public string getName ( )

                public function getName(): string
{
    return self::class;
}

            
getSummary() public method

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)
                )
            )
        ),
    ];
}

            
shutdown() public method
public void shutdown ( )

                public function shutdown(): void
{
    $this->reset();
    $this->isActive = false;
}

            
startup() public method
public void startup ( )

                public function startup(): void
{
    $this->isActive = true;
}