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.
 
 

102 lines
2.9 KiB

<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\debug\panels;
use Yii;
use yii\base\InlineAction;
use yii\debug\Panel;
/**
* Debugger panel that collects and displays request data.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class RequestPanel extends Panel
{
public function getName()
{
return 'Request';
}
public function getSummary()
{
return Yii::$app->view->render('panels/request/summary', [
'panel' => $this,
'data' => $this->data,
]);
}
public function getDetail()
{
return Yii::$app->view->render('panels/request/detail', [
'panel' => $this,
'data' => [
'Route' => $this->data['route'],
'Action' => $this->data['action'],
'Parameters' => $this->data['actionParams'],
],
]);
}
public function save()
{
if (function_exists('apache_request_headers')) {
$requestHeaders = apache_request_headers();
} elseif (function_exists('http_get_request_headers')) {
$requestHeaders = http_get_request_headers();
} else {
$requestHeaders = [];
}
$responseHeaders = [];
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])) {
$responseHeaders[$name] = [$responseHeaders[$name], $value];
} 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);
return [
'flashes' => $session ? $session->getAllFlashes() : [],
'statusCode' => Yii::$app->getResponse()->getStatusCode(),
'requestHeaders' => $requestHeaders,
'responseHeaders' => $responseHeaders,
'route' => Yii::$app->requestedAction ? Yii::$app->requestedAction->getUniqueId() : Yii::$app->requestedRoute,
'action' => $action,
'actionParams' => Yii::$app->requestedParams,
'SERVER' => empty($_SERVER) ? [] : $_SERVER,
'GET' => empty(Yii::$app->request->get()) ? [] : Yii::$app->request->get(),
'POST' => empty(Yii::$app->request->post()) ? [] : Yii::$app->request->post(),
'COOKIE' => empty(Yii::$app->request->cookies) ? [] : Yii::$app->request->cookies,
'FILES' => empty($_FILES) ? [] : $_FILES,
'SESSION' => empty(Yii::$app->session) ? [] : Yii::$app->session,
];
}
}