|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- <?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
- {
- /**
- * @inheritdoc
- */
- public function getName()
- {
- return 'Request';
- }
-
- /**
- * @inheritdoc
- */
- public function getSummary()
- {
- return Yii::$app->view->render('panels/request/summary', ['panel' => $this]);
- }
-
- /**
- * @inheritdoc
- */
- public function getDetail()
- {
- return Yii::$app->view->render('panels/request/detail', ['panel' => $this]);
- }
-
- /**
- * @inheritdoc
- */
- public function save()
- {
- $headers = Yii::$app->getRequest()->getHeaders();
- $requestHeaders = [];
- foreach ($headers as $name => $value) {
- if (is_array($value) && count($value) == 1) {
- $requestHeaders[$name] = current($value);
- } else {
- $requestHeaders[$name] = $value;
- }
- }
-
- $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;
- }
-
- return [
- 'flashes' => $this->getFlashes(),
- '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,
- 'requestBody' => Yii::$app->getRequest()->getRawBody() == '' ? [] : [
- 'Content Type' => Yii::$app->getRequest()->getContentType(),
- 'Raw' => Yii::$app->getRequest()->getRawBody(),
- 'Decoded to Params' => Yii::$app->getRequest()->getBodyParams(),
- ],
- 'SERVER' => empty($_SERVER) ? [] : $_SERVER,
- 'GET' => empty($_GET) ? [] : $_GET,
- 'POST' => empty($_POST) ? [] : $_POST,
- 'COOKIE' => empty($_COOKIE) ? [] : $_COOKIE,
- 'FILES' => empty($_FILES) ? [] : $_FILES,
- 'SESSION' => empty($_SESSION) ? [] : $_SESSION,
- ];
- }
-
- /**
- * Getting flash messages without deleting them or touching deletion counters
- *
- * @return array flash messages (key => message).
- */
- protected function getFlashes()
- {
- /* @var $session \yii\web\Session */
- $session = Yii::$app->has('session', true) ? Yii::$app->get('session') : null;
- if ($session === null || !$session->getIsActive()) {
- return [];
- }
-
- $counters = $session->get($session->flashParam, []);
- $flashes = [];
- foreach (array_keys($counters) as $key) {
- if (array_key_exists($key, $_SESSION)) {
- $flashes[$key] = $_SESSION[$key];
- }
- }
- return $flashes;
- }
- }
|