Class yii\httpclient\debug\HttpClientPanel
| Inheritance | yii\httpclient\debug\HttpClientPanel » yii\debug\Panel |
|---|---|
| Available since extension's version | 2.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
| 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 |
Public Methods
| Method | Description | Defined By |
|---|---|---|
| calculateTimings() | Calculates given request profile timings. | yii\httpclient\debug\HttpClientPanel |
| getDetail() | yii\httpclient\debug\HttpClientPanel | |
| getHttpClient() | yii\httpclient\debug\HttpClientPanel | |
| getMethods() | Returns array request methods | yii\httpclient\debug\HttpClientPanel |
| getName() | yii\httpclient\debug\HttpClientPanel | |
| getSummary() | yii\httpclient\debug\HttpClientPanel | |
| getTypes() | Returns array request types | yii\httpclient\debug\HttpClientPanel |
| init() | yii\httpclient\debug\HttpClientPanel | |
| save() | yii\httpclient\debug\HttpClientPanel | |
| setHttpClient() | yii\httpclient\debug\HttpClientPanel |
Protected 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
Note that the type of this property differs in getter and setter. See getHttpClient() and setHttpClient() for details.
Method Details
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;
}
| 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,
]);
}
| 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;
}
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;
},
[]
);
}
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;
}
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] : '';
}
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';
}
| 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,
]);
}
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;
}
Returns array request types
| public array getTypes ( ) |
public function getTypes()
{
return [
'normal' => 'Normal',
'batch' => 'Batch',
];
}
| public void init ( ) |
public function init()
{
$this->actions['request-execute'] = [
'class' => 'yii\httpclient\debug\RequestExecuteAction',
'panel' => $this,
];
}
| 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];
}
| public void setHttpClient ( $httpClient ) | ||
| $httpClient | array | |
public function setHttpClient($httpClient)
{
$this->_httpClient = $httpClient;
}