Browse Source

Merge pull request #1729 from Ragazzo/debug_module_request_panel_improvements

debug module request panel improved
tags/2.0.0-beta
Qiang Xue 11 years ago
parent
commit
eaf4d3ca1b
  1. 87
      extensions/yii/debug/panels/RequestPanel.php
  2. 24
      extensions/yii/debug/views/default/panels/request/_data_table.php
  3. 31
      extensions/yii/debug/views/default/panels/request/detail.php
  4. 23
      extensions/yii/debug/views/default/panels/request/summary.php

87
extensions/yii/debug/panels/RequestPanel.php

@ -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
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', [
'panel' => $this,
'data' => [
'Route' => $this->data['route'], 'Route' => $this->data['route'],
'Action' => $this->data['action'], 'Action' => $this->data['action'],
'Parameters' => $this->data['actionParams'], 'Parameters' => $this->data['actionParams'],
];
return Tabs::widget([
'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;
'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;
}
} }

24
extensions/yii/debug/views/default/panels/request/_data_table.php

@ -0,0 +1,24 @@
<?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; ?>

31
extensions/yii/debug/views/default/panels/request/detail.php

@ -0,0 +1,31 @@
<?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']]),
],
],
]);
?>

23
extensions/yii/debug/views/default/panels/request/summary.php

@ -0,0 +1,23 @@
<?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>
Loading…
Cancel
Save