Class yii\httpclient\debug\HttpClientPanel

Inheritanceyii\httpclient\debug\HttpClientPanel » yii\debug\Panel
Available since extension's version2.0
Source Code https://github.com/yiisoft/yii2-httpclient/blob/master/src/debug/HttpClientPanel.php

Debugger panel that collects and displays HTTP requests performed.

Public Properties

Hide inherited properties

Property Type Description Defined By
$httpClient yii\httpclient\Client Note that the type of this property differs in getter and setter. yii\httpclient\debug\HttpClientPanel
$methods array This property is read-only. yii\httpclient\debug\HttpClientPanel
$types array This property is read-only. yii\httpclient\debug\HttpClientPanel

Protected Methods

Hide inherited methods

Method Description Defined By
getModels() Returns an array of models that represents logs of the current request. yii\httpclient\debug\HttpClientPanel
getRequestMethod() Returns HTTP request method. yii\httpclient\debug\HttpClientPanel
getRequestType() Returns request type. yii\httpclient\debug\HttpClientPanel
getTotalRequestTime() Returns total request time. yii\httpclient\debug\HttpClientPanel

Property Details

Hide inherited properties

$httpClient public property

Note that the type of this property differs in getter and setter. See getHttpClient() and setHttpClient() for details.

$methods public property

This property is read-only.

public array $methods null
$types public property

This property is read-only.

public array $types null

Method Details

Hide inherited methods

calculateTimings() public method

Calculates given request profile timings.

public array calculateTimings ( )
return array

Timings [token, category, timestamp, traces, nesting level, elapsed time]

                public function calculateTimings()
{
    if ($this->_timings === null) {
        $this->_timings = Yii::getLogger()->calculateTimings(isset($this->data['messages']) ? $this->data['messages'] : []);
    }
    return $this->_timings;
}

            
getDetail() public method

public void getDetail ( )

                public function getDetail()
{
    $searchModel = new SearchModel();
    $dataProvider = $searchModel->search(Yii::$app->request->getQueryParams(), $this->getModels());
    return Yii::$app->view->render('@yii/httpclient/debug/views/detail', [
        'panel' => $this,
        'dataProvider' => $dataProvider,
        'searchModel' => $searchModel,
    ]);
}

            
getHttpClient() public method

public yii\httpclient\Client getHttpClient ( )
throws \yii\base\InvalidConfigException

                public function getHttpClient()
{
    if (!is_object($this->_httpClient)) {
        $this->_httpClient = Instance::ensure($this->_httpClient, Client::className());
    }
    return $this->_httpClient;
}

            
getMethods() public method

Returns array request methods

public array getMethods ( )

                public function getMethods()
{
    return array_reduce(
        $this->_models,
        function ($result, $item) {
            $result[$item['method']] = $item['method'];
            return $result;
        },
        []
    );
}

            
getModels() protected method

Returns an array of models that represents logs of the current request.

Can be used with data providers such as \yii\data\ArrayDataProvider.

protected array getModels ( )
return array

Models

                protected function getModels()
{
    if ($this->_models === null) {
        $this->_models = [];
        $timings = $this->calculateTimings();
        foreach ($timings as $seq => $dbTiming) {
            $this->_models[] = [
                'method' => $this->getRequestMethod($dbTiming['info']),
                'type' => $this->getRequestType($dbTiming['category']),
                'request' => $dbTiming['info'],
                'duration' => ($dbTiming['duration'] * 1000), // in milliseconds
                'trace' => $dbTiming['trace'],
                'timestamp' => ($dbTiming['timestamp'] * 1000), // in milliseconds
                'seq' => $seq,
            ];
        }
    }
    return $this->_models;
}

            
getName() public method

public void getName ( )

                public function getName()
{
    return 'HTTP Client';
}

            
getRequestMethod() protected method

Returns HTTP request method.

protected string getRequestMethod ( $timing )
$timing string

Timing procedure string

return string

Request method such as GET, POST, PUT, etc.

                protected function getRequestMethod($timing)
{
    $timing = ltrim($timing);
    preg_match('/^([a-zA-z]*)/', $timing, $matches);
    return count($matches) ? $matches[0] : '';
}

            
getRequestType() protected method

Returns request type.

protected string getRequestType ( $category )
$category string
return string

Request type such as 'normal', 'batch'

                protected function getRequestType($category)
{
    return (stripos($category, '::batchSend') === false) ? 'normal' : 'batch';
}

            
getSummary() public method

public void getSummary ( )

                public function getSummary()
{
    $timings = $this->calculateTimings();
    $queryCount = count($timings);
    if ($queryCount === 0) {
        return '';
    }
    $queryTime = number_format($this->getTotalRequestTime($timings) * 1000) . ' ms';
    return Yii::$app->view->render('@yii/httpclient/debug/views/summary', [
        'timings' => $this->calculateTimings(),
        'panel' => $this,
        'queryCount' => $queryCount,
        'queryTime' => $queryTime,
    ]);
}

            
getTotalRequestTime() protected method

Returns total request time.

protected integer getTotalRequestTime ( $timings )
$timings array
return integer

Total time

                protected function getTotalRequestTime($timings)
{
    $queryTime = 0;
    foreach ($timings as $timing) {
        $queryTime += $timing['duration'];
    }
    return $queryTime;
}

            
getTypes() public method

Returns array request types

public array getTypes ( )

                public function getTypes()
{
    return [
        'normal' => 'Normal',
        'batch' => 'Batch',
    ];
}

            
init() public method

public void init ( )

                public function init()
{
    $this->actions['request-execute'] = [
        'class' => 'yii\httpclient\debug\RequestExecuteAction',
        'panel' => $this,
    ];
}

            
save() public method

public void save ( )

                public function save()
{
    $target = $this->module->logTarget;
    $messages = $target->filterMessages($target->messages, Logger::LEVEL_PROFILE, [
        'yii\httpclient\Transport::*',
        'yii\httpclient\CurlTransport::*',
        'yii\httpclient\StreamTransport::*',
    ]);
    return ['messages' => $messages];
}

            
setHttpClient() public method

public void setHttpClient ( $httpClient )
$httpClient array

                public function setHttpClient($httpClient)
{
    $this->_httpClient = $httpClient;
}