Final Class Yiisoft\Yii\Debug\Collector\Web\RequestCollector
| Inheritance | Yiisoft\Yii\Debug\Collector\Web\RequestCollector |
|---|---|
| Implements | Yiisoft\Yii\Debug\Collector\SummaryCollectorInterface |
| Uses Traits | Yiisoft\Yii\Debug\Collector\CollectorTrait |
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 ( object $event ) | ||
| $event | object | |
public function collect(object $event): void
{
if (!$this->isActive()) {
return;
}
if ($event instanceof BeforeRequest) {
$request = $event->getRequest();
$this->request = $request;
$this->requestUrl = (string) $request->getUri();
$this->requestPath = $request->getUri()->getPath();
$this->requestQuery = $request->getUri()->getQuery();
$this->requestMethod = $request->getMethod();
$this->requestIsAjax = strtolower($request->getHeaderLine('X-Requested-With')) === 'xmlhttprequest';
$this->userIp = $request->getServerParams()['REMOTE_ADDR'] ?? null;
}
if ($event instanceof AfterRequest) {
$response = $event->getResponse();
$this->response = $response;
$this->responseStatusCode = $response !== null ? $response->getStatusCode() : 500;
}
$this->timelineCollector->collect($this, spl_object_id($event));
}
| public array getCollected ( ) |
public function getCollected(): array
{
if (!$this->isActive()) {
return [];
}
$requestRaw = null;
if ($this->request instanceof ServerRequestInterface) {
$requestRaw = Message::toString($this->request);
Message::rewindBody($this->request);
}
$responseRaw = null;
if ($this->response instanceof ResponseInterface) {
$responseRaw = Message::toString($this->response);
Message::rewindBody($this->response);
}
return [
'requestUrl' => $this->requestUrl,
'requestPath' => $this->requestPath,
'requestQuery' => $this->requestQuery,
'requestMethod' => $this->requestMethod,
'requestIsAjax' => $this->requestIsAjax,
'userIp' => $this->userIp,
'responseStatusCode' => $this->responseStatusCode,
'request' => $this->request,
'requestRaw' => $requestRaw,
'response' => $this->response,
'responseRaw' => $responseRaw,
];
}
| public array getSummary ( ) |
public function getSummary(): array
{
if (!$this->isActive()) {
return [];
}
return [
'request' => [
'url' => $this->requestUrl,
'path' => $this->requestPath,
'query' => $this->requestQuery,
'method' => $this->requestMethod,
'isAjax' => $this->requestIsAjax,
'userIp' => $this->userIp,
],
'response' => [
'statusCode' => $this->responseStatusCode,
],
];
}
| public void shutdown ( ) |
public function shutdown(): void
{
$this->reset();
$this->isActive = false;
}
Signup or Login in order to comment.