You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
168 lines
4.9 KiB
168 lines
4.9 KiB
12 years ago
|
<?php
|
||
|
/**
|
||
|
* @link http://www.yiiframework.com/
|
||
|
* @copyright Copyright (c) 2008 Yii Software LLC
|
||
|
* @license http://www.yiiframework.com/license/
|
||
|
*/
|
||
|
|
||
|
namespace yii\debug\panels;
|
||
|
|
||
12 years ago
|
use Yii;
|
||
|
use yii\base\InlineAction;
|
||
12 years ago
|
use yii\bootstrap\Tabs;
|
||
12 years ago
|
use yii\debug\Panel;
|
||
12 years ago
|
use yii\helpers\Html;
|
||
12 years ago
|
use yii\web\Response;
|
||
12 years ago
|
|
||
|
/**
|
||
12 years ago
|
* Debugger panel that collects and displays request data.
|
||
|
*
|
||
12 years ago
|
* @author Qiang Xue <qiang.xue@gmail.com>
|
||
|
* @since 2.0
|
||
|
*/
|
||
|
class RequestPanel extends Panel
|
||
|
{
|
||
|
public function getName()
|
||
|
{
|
||
|
return 'Request';
|
||
|
}
|
||
|
|
||
|
public function getSummary()
|
||
|
{
|
||
12 years ago
|
$url = $this->getUrl();
|
||
12 years ago
|
$statusCode = $this->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] : '');
|
||
12 years ago
|
|
||
|
return <<<EOD
|
||
|
<div class="yii-debug-toolbar-block">
|
||
12 years ago
|
<a href="$url" title="Status code: $statusCode $statusText">Status <span class="label $class">$statusCode</span></a>
|
||
12 years ago
|
</div>
|
||
|
<div class="yii-debug-toolbar-block">
|
||
12 years ago
|
<a href="$url">Action <span class="label">{$this->data['action']}</span></a>
|
||
12 years ago
|
</div>
|
||
12 years ago
|
EOD;
|
||
|
}
|
||
|
|
||
|
public function getDetail()
|
||
|
{
|
||
11 years ago
|
$data = [
|
||
12 years ago
|
'Route' => $this->data['route'],
|
||
|
'Action' => $this->data['action'],
|
||
|
'Parameters' => $this->data['actionParams'],
|
||
11 years ago
|
];
|
||
|
return Tabs::widget([
|
||
|
'items' => [
|
||
|
[
|
||
12 years ago
|
'label' => 'Parameters',
|
||
|
'content' => $this->renderData('Routing', $data)
|
||
|
. $this->renderData('$_GET', $this->data['GET'])
|
||
|
. $this->renderData('$_POST', $this->data['POST'])
|
||
12 years ago
|
. $this->renderData('$_FILES', $this->data['FILES'])
|
||
12 years ago
|
. $this->renderData('$_COOKIE', $this->data['COOKIE']),
|
||
|
'active' => true,
|
||
11 years ago
|
],
|
||
|
[
|
||
12 years ago
|
'label' => 'Headers',
|
||
|
'content' => $this->renderData('Request Headers', $this->data['requestHeaders'])
|
||
|
. $this->renderData('Response Headers', $this->data['responseHeaders']),
|
||
11 years ago
|
],
|
||
|
[
|
||
12 years ago
|
'label' => 'Session',
|
||
|
'content' => $this->renderData('$_SESSION', $this->data['SESSION'])
|
||
|
. $this->renderData('Flashes', $this->data['flashes']),
|
||
11 years ago
|
],
|
||
|
[
|
||
12 years ago
|
'label' => '$_SERVER',
|
||
|
'content' => $this->renderData('$_SERVER', $this->data['SERVER']),
|
||
11 years ago
|
],
|
||
|
],
|
||
|
]);
|
||
12 years ago
|
}
|
||
|
|
||
|
public function save()
|
||
|
{
|
||
12 years ago
|
if (function_exists('apache_request_headers')) {
|
||
|
$requestHeaders = apache_request_headers();
|
||
|
} elseif (function_exists('http_get_request_headers')) {
|
||
|
$requestHeaders = http_get_request_headers();
|
||
|
} else {
|
||
11 years ago
|
$requestHeaders = [];
|
||
12 years ago
|
}
|
||
11 years ago
|
$responseHeaders = [];
|
||
12 years ago
|
foreach (headers_list() as $header) {
|
||
|
if (($pos = strpos($header, ':')) !== false) {
|
||
|
$name = substr($header, 0, $pos);
|
||
|
$value = trim(substr($header, $pos + 1));
|
||
|
if (isset($responseHeaders[$name])) {
|
||
|
if (!is_array($responseHeaders[$name])) {
|
||
11 years ago
|
$responseHeaders[$name] = [$responseHeaders[$name], $value];
|
||
12 years ago
|
} else {
|
||
|
$responseHeaders[$name][] = $value;
|
||
|
}
|
||
|
} else {
|
||
|
$responseHeaders[$name] = $value;
|
||
|
}
|
||
|
} else {
|
||
|
$responseHeaders[] = $header;
|
||
|
}
|
||
|
}
|
||
|
if (Yii::$app->requestedAction) {
|
||
|
if (Yii::$app->requestedAction instanceof InlineAction) {
|
||
|
$action = get_class(Yii::$app->requestedAction->controller) . '::' . Yii::$app->requestedAction->actionMethod . '()';
|
||
|
} else {
|
||
|
$action = get_class(Yii::$app->requestedAction) . '::run()';
|
||
|
}
|
||
|
} else {
|
||
|
$action = null;
|
||
|
}
|
||
|
/** @var \yii\web\Session $session */
|
||
|
$session = Yii::$app->getComponent('session', false);
|
||
11 years ago
|
return [
|
||
|
'flashes' => $session ? $session->getAllFlashes() : [],
|
||
12 years ago
|
'statusCode' => Yii::$app->getResponse()->getStatusCode(),
|
||
12 years ago
|
'requestHeaders' => $requestHeaders,
|
||
|
'responseHeaders' => $responseHeaders,
|
||
12 years ago
|
'route' => Yii::$app->requestedAction ? Yii::$app->requestedAction->getUniqueId() : Yii::$app->requestedRoute,
|
||
12 years ago
|
'action' => $action,
|
||
|
'actionParams' => Yii::$app->requestedParams,
|
||
11 years ago
|
'SERVER' => empty($_SERVER) ? [] : $_SERVER,
|
||
|
'GET' => empty($_GET) ? [] : $_GET,
|
||
|
'POST' => empty($_POST) ? [] : $_POST,
|
||
|
'COOKIE' => empty($_COOKIE) ? [] : $_COOKIE,
|
||
|
'FILES' => empty($_FILES) ? [] : $_FILES,
|
||
|
'SESSION' => empty($_SESSION) ? [] : $_SESSION,
|
||
|
];
|
||
12 years ago
|
}
|
||
12 years ago
|
|
||
12 years ago
|
protected function renderData($caption, $values)
|
||
12 years ago
|
{
|
||
12 years ago
|
if (empty($values)) {
|
||
|
return "<h3>$caption</h3>\n<p>Empty.</p>";
|
||
|
}
|
||
11 years ago
|
$rows = [];
|
||
12 years ago
|
foreach ($values as $name => $value) {
|
||
11 years ago
|
$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>';
|
||
12 years ago
|
}
|
||
12 years ago
|
$rows = implode("\n", $rows);
|
||
|
return <<<EOD
|
||
|
<h3>$caption</h3>
|
||
12 years ago
|
<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;
|
||
12 years ago
|
}
|
||
12 years ago
|
}
|