Commit c79cbb38 by Mark

debug module request panel improved

parent 7a1949fe
...@@ -9,10 +9,7 @@ namespace yii\debug\panels; ...@@ -9,10 +9,7 @@ namespace yii\debug\panels;
use Yii; use Yii;
use yii\base\InlineAction; use yii\base\InlineAction;
use yii\bootstrap\Tabs;
use yii\debug\Panel; use yii\debug\Panel;
use yii\helpers\Html;
use yii\web\Response;
/** /**
* Debugger panel that collects and displays request data. * Debugger panel that collects and displays request data.
...@@ -29,62 +26,20 @@ class RequestPanel extends Panel ...@@ -29,62 +26,20 @@ class RequestPanel extends Panel
public function getSummary() public function getSummary()
{ {
$url = $this->getUrl(); return Yii::$app->view->render('panels/request/summary', [
$statusCode = $this->data['statusCode']; 'panel' => $this,
if ($statusCode === null) { 'data' => $this->data,
$statusCode = 200; ]);
}
if ($statusCode >= 200 && $statusCode < 300) {
$class = 'label-success';
} elseif ($statusCode >= 100 && $statusCode < 200) {
$class = 'label-info';
} else {
$class = 'label-important';
}
$statusText = Html::encode(isset(Response::$httpStatuses[$statusCode]) ? Response::$httpStatuses[$statusCode] : '');
return <<<EOD
<div class="yii-debug-toolbar-block">
<a href="$url" title="Status code: $statusCode $statusText">Status <span class="label $class">$statusCode</span></a>
</div>
<div class="yii-debug-toolbar-block">
<a href="$url">Action <span class="label">{$this->data['action']}</span></a>
</div>
EOD;
} }
public function getDetail() public function getDetail()
{ {
$data = [ return Yii::$app->view->render('panels/request/detail', [
'Route' => $this->data['route'], 'panel' => $this,
'Action' => $this->data['action'], 'data' => [
'Parameters' => $this->data['actionParams'], 'Route' => $this->data['route'],
]; 'Action' => $this->data['action'],
return Tabs::widget([ 'Parameters' => $this->data['actionParams'],
'items' => [
[
'label' => 'Parameters',
'content' => $this->renderData('Routing', $data)
. $this->renderData('$_GET', $this->data['GET'])
. $this->renderData('$_POST', $this->data['POST'])
. $this->renderData('$_FILES', $this->data['FILES'])
. $this->renderData('$_COOKIE', $this->data['COOKIE']),
'active' => true,
],
[
'label' => 'Headers',
'content' => $this->renderData('Request Headers', $this->data['requestHeaders'])
. $this->renderData('Response Headers', $this->data['responseHeaders']),
],
[
'label' => 'Session',
'content' => $this->renderData('$_SESSION', $this->data['SESSION'])
. $this->renderData('Flashes', $this->data['flashes']),
],
[
'label' => '$_SERVER',
'content' => $this->renderData('$_SERVER', $this->data['SERVER']),
],
], ],
]); ]);
} }
...@@ -136,32 +91,12 @@ EOD; ...@@ -136,32 +91,12 @@ EOD;
'action' => $action, 'action' => $action,
'actionParams' => Yii::$app->requestedParams, 'actionParams' => Yii::$app->requestedParams,
'SERVER' => empty($_SERVER) ? [] : $_SERVER, 'SERVER' => empty($_SERVER) ? [] : $_SERVER,
'GET' => empty($_GET) ? [] : $_GET, 'GET' => empty(Yii::$app->request->get()) ? [] : Yii::$app->request->get(),
'POST' => empty($_POST) ? [] : $_POST, 'POST' => empty(Yii::$app->request->post()) ? [] : Yii::$app->request->post(),
'COOKIE' => empty($_COOKIE) ? [] : $_COOKIE, 'COOKIE' => empty(Yii::$app->request->cookies) ? [] : Yii::$app->request->cookies,
'FILES' => empty($_FILES) ? [] : $_FILES, 'FILES' => empty($_FILES) ? [] : $_FILES,
'SESSION' => empty($_SESSION) ? [] : $_SESSION, 'SESSION' => empty(Yii::$app->session) ? [] : Yii::$app->session,
]; ];
} }
protected function renderData($caption, $values)
{
if (empty($values)) {
return "<h3>$caption</h3>\n<p>Empty.</p>";
}
$rows = [];
foreach ($values as $name => $value) {
$rows[] = '<tr><th style="width: 200px;">' . Html::encode($name) . '</th><td>' . htmlspecialchars(var_export($value, true), ENT_QUOTES|ENT_SUBSTITUTE, \Yii::$app->charset, TRUE) . '</td></tr>';
}
$rows = implode("\n", $rows);
return <<<EOD
<h3>$caption</h3>
<table class="table table-condensed table-bordered table-striped table-hover" style="table-layout: fixed;">
<thead><tr><th style="width: 200px;">Name</th><th>Value</th></tr></thead>
<tbody>
$rows
</tbody>
</table>
EOD;
}
} }
<?php
use yii\helpers\Html;
if (empty($values)): ?>
<h3><?php echo $caption; ?></h3>
<p>Empty.</p>
<?php else: ?>
<h3><?php echo $caption; ?></h3>
<table class="table table-condensed table-bordered table-striped table-hover" style="table-layout: fixed;">
<thead>
<tr>
<th style="width: 200px;">Name</th>
<th>Value</th>
</tr>
</thead>
<?php foreach($values as $name => $value): ?>
<tr>
<th style="width: 200px;"><?php echo Html::encode($name); ?></th>
<td><?php echo htmlspecialchars(var_export($value, true), ENT_QUOTES|ENT_SUBSTITUTE, \Yii::$app->charset, TRUE); ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php endif; ?>
\ No newline at end of file
<?php
use yii\bootstrap\Tabs;
echo Tabs::widget([
'items' => [
[
'label' => 'Parameters',
'content' => $this->context->renderPartial('panels/request/_data_table', ['caption' => 'Routing', 'values' => $data])
. $this->context->renderPartial('panels/request/_data_table', ['caption' => '$_GET', 'values' => $panel->data['GET']])
. $this->context->renderPartial('panels/request/_data_table', ['caption' => '$_POST', 'values' => $panel->data['POST']])
. $this->context->renderPartial('panels/request/_data_table', ['caption' => '$_FILES', 'values' => $panel->data['FILES']])
. $this->context->renderPartial('panels/request/_data_table', ['caption' => '$_COOKIE', 'values' => $panel->data['COOKIE']]),
'active' => true,
],
[
'label' => 'Headers',
'content' => $this->context->renderPartial('panels/request/_data_table', ['caption' => 'Request Headers', 'values' => $panel->data['requestHeaders']])
. $this->context->renderPartial('panels/request/_data_table', ['caption' => 'Response Headers', 'values' => $panel->data['responseHeaders']])
],
[
'label' => 'Session',
'content' => $this->context->renderPartial('panels/request/_data_table', ['caption' => '$_SESSION', 'values' => $panel->data['SESSION']])
. $this->context->renderPartial('panels/request/_data_table', ['caption' => 'Flashes', 'values' => $panel->data['flashes']])
],
[
'label' => '$_SERVER',
'content' => $this->context->renderPartial('panels/request/_data_table', ['caption' => '$_SERVER', 'values' => $panel->data['SERVER']]),
],
],
]);
?>
\ No newline at end of file
<?php
use yii\helpers\Html;
use yii\web\Response;
$statusCode = $data['statusCode'];
if ($statusCode === null) {
$statusCode = 200;
}
if ($statusCode >= 200 && $statusCode < 300) {
$class = 'label-success';
} elseif ($statusCode >= 100 && $statusCode < 200) {
$class = 'label-info';
} else {
$class = 'label-important';
}
$statusText = Html::encode(isset(Response::$httpStatuses[$statusCode]) ? Response::$httpStatuses[$statusCode] : '');
?>
<div class="yii-debug-toolbar-block">
<a href="<?php echo $panel->getUrl(); ?>" title="Status code: <?php echo $statusCode; ?> <?php echo $statusText; ?>">Status <span class="label <?php echo $class; ?>"><?php echo $statusCode; ?></span></a>
</div>
<div class="yii-debug-toolbar-block">
<a href="<?php echo $panel->getUrl(); ?>">Action <span class="label"><?php echo $data['action']; ?></span></a>
</div>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment