Class yii\debug\panels\RequestPanel
Inheritance | yii\debug\panels\RequestPanel » yii\debug\Panel » yii\base\Component |
---|---|
Available since extension's version | 2.0 |
Source Code | https://github.com/yiisoft/yii2-debug/blob/master/src/panels/RequestPanel.php |
Debugger panel that collects and displays request data.
Public Properties
Property | Type | Description | Defined By |
---|---|---|---|
$actions | array | Array of actions to add to the debug modules default controller. | yii\debug\Panel |
$censorString | string | Value to display instead of the variable value if the name is on the censor list | yii\debug\panels\RequestPanel |
$censoredVariableNames | array | List of variable names which values should be censored in the output | yii\debug\panels\RequestPanel |
$data | mixed | Data associated with panel | yii\debug\Panel |
$detail | string | Content that is displayed in debugger detail view. | yii\debug\Panel |
$displayVars | array | List of the PHP predefined variables that are allowed to be displayed in the request panel. | yii\debug\panels\RequestPanel |
$error | yii\debug\FlattenException|null | Error while saving the panel | yii\debug\Panel |
$id | string | Panel unique identifier. | yii\debug\Panel |
$module | yii\debug\Module | yii\debug\Panel | |
$name | string | Name of the panel. | yii\debug\Panel |
$summary | string | Content that is displayed at debug toolbar. | yii\debug\Panel |
$tag | string | Request data set identifier. | yii\debug\Panel |
$url | string | URL pointing to panel detail view. | yii\debug\Panel |
Public Methods
Method | Description | Defined By |
---|---|---|
getDetail() | yii\debug\panels\RequestPanel | |
getError() | yii\debug\Panel | |
getName() | yii\debug\panels\RequestPanel | |
getSummary() | yii\debug\panels\RequestPanel | |
getTraceLine() | Returns a trace line | yii\debug\Panel |
getUrl() | yii\debug\Panel | |
hasError() | yii\debug\Panel | |
isEnabled() | Checks whether this panel is enabled. | yii\debug\Panel |
load() | Loads data into the panel | yii\debug\Panel |
save() | Saves data to be later used in debugger detail view. | yii\debug\panels\RequestPanel |
setError() | yii\debug\Panel |
Protected Methods
Method | Description | Defined By |
---|---|---|
censorArray() | yii\debug\panels\RequestPanel | |
getFlashes() | Getting flash messages without deleting them or touching deletion counters | yii\debug\panels\RequestPanel |
getLogMessages() | Gets messages from log target and filters according to their categories and levels. | yii\debug\Panel |
Property Details
Value to display instead of the variable value if the name is on the censor list
List of variable names which values should be censored in the output
List of the PHP predefined variables that are allowed to be displayed in the request panel.
Note that a variable must be accessible via $GLOBALS
. Otherwise it won't be displayed.
Method Details
protected array censorArray ( $data ) | ||
$data | array |
protected function censorArray($data)
{
if (empty($this->censoredVariableNames) || empty($data)) {
return $data;
}
foreach ($this->censoredVariableNames as $var) {
$key = ltrim($var, '_');
if (ArrayHelper::getValue($data, $key) !== null) {
ArrayHelper::setValue($data, $key, $this->censorString);
if (strpos($key, 'requestBody') === 0) {
ArrayHelper::setValue($data, 'requestBody.Raw', $this->censorString);
}
}
}
return $data;
}
public string getDetail ( ) | ||
return | string |
Content that is displayed in debugger detail view |
---|
public function getDetail()
{
return Yii::$app->view->render('panels/request/detail', ['panel' => $this]);
}
Defined in: yii\debug\Panel::getError()
public yii\debug\FlattenException|null getError ( ) |
public function getError()
{
return $this->error;
}
Getting flash messages without deleting them or touching deletion counters
protected array getFlashes ( ) | ||
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;
}
Defined in: yii\debug\Panel::getLogMessages()
Gets messages from log target and filters according to their categories and levels.
See also \yii\log\Target::filterMessages().
protected array getLogMessages ( $levels = 0, $categories = [], $except = [], $stringify = false ) | ||
$levels | integer |
The message levels to filter by. This is a bitmap of level values. Value 0 means allowing all levels. |
$categories | array |
The message categories to filter by. If empty, it means all categories are allowed. |
$except | array |
The message categories to exclude. If empty, it means all categories are allowed. |
$stringify | boolean |
Convert non-string (such as closures) to strings |
return | array |
The filtered messages. |
---|
protected function getLogMessages($levels = 0, $categories = [], $except = [], $stringify = false)
{
$target = $this->module->logTarget;
$messages = $target->filterMessages($target->messages, $levels, $categories, $except);
if (!$stringify) {
return $messages;
}
foreach ($messages as &$message) {
if (!isset($message[0]) || is_string($message[0])) {
continue;
}
// exceptions may not be serializable if in the call stack somewhere is a Closure
if ($message[0] instanceof \Throwable || $message[0] instanceof \Exception) {
$message[0] = (string) $message[0];
} else {
$message[0] = VarDumper::export($message[0]);
}
}
return $messages;
}
public string getName ( ) | ||
return | string |
Name of the panel |
---|
public function getName()
{
return 'Request';
}
public string getSummary ( ) | ||
return | string |
Content that is displayed at debug toolbar |
---|
public function getSummary()
{
return Yii::$app->view->render('panels/request/summary', ['panel' => $this]);
}
Defined in: yii\debug\Panel::getTraceLine()
Returns a trace line
public string getTraceLine ( $options ) | ||
$options | array |
The array with trace |
return | string |
The trace line |
---|
public function getTraceLine($options)
{
if (!isset($options['text'])) {
$options['text'] = "{$options['file']}:{$options['line']}";
}
$traceLine = $this->module->traceLine;
if ($traceLine === false) {
return $options['text'];
}
$options['file'] = str_replace('\\', '/', $options['file']);
foreach ($this->module->tracePathMappings as $old => $new) {
$old = rtrim(str_replace('\\', '/', $old), '/') . '/';
if (StringHelper::startsWith($options['file'], $old)) {
$new = rtrim(str_replace('\\', '/', $new), '/') . '/';
$options['file'] = $new . substr($options['file'], strlen($old));
break;
}
}
$rawLink = $traceLine instanceof \Closure ? $traceLine($options, $this) : $traceLine;
return strtr($rawLink, ['{file}' => $options['file'], '{line}' => $options['line'], '{text}' => $options['text']]);
}
Defined in: yii\debug\Panel::getUrl()
public string getUrl ( $additionalParams = null ) | ||
$additionalParams | null|array |
Optional additional parameters to add to the route |
return | string |
URL pointing to panel detail view |
---|
public function getUrl($additionalParams = null)
{
$route = [
'/' . $this->module->getUniqueId() . '/default/view',
'panel' => $this->id,
'tag' => $this->tag,
];
if (is_array($additionalParams)) {
$route = ArrayHelper::merge($route, $additionalParams);
}
return Url::toRoute($route);
}
Defined in: yii\debug\Panel::hasError()
public boolean hasError ( ) |
public function hasError()
{
return $this->error !== null;
}
Defined in: yii\debug\Panel::isEnabled()
Checks whether this panel is enabled.
public boolean isEnabled ( ) | ||
return | boolean |
Whether this panel is enabled. |
---|
public function isEnabled()
{
return true;
}
Defined in: yii\debug\Panel::load()
Loads data into the panel
public void load ( $data ) | ||
$data | mixed |
public function load($data)
{
$this->data = $data;
}
Saves data to be later used in debugger detail view.
This method is called on every page where debugger is enabled.
public mixed save ( ) | ||
return | mixed |
Data to be saved |
---|
public function save()
{
$headers = Yii::$app->getRequest()->getHeaders();
$requestHeaders = [];
$hasCensorList = count($this->censoredVariableNames);
foreach ($headers as $name => $value) {
if ($hasCensorList && in_array($name, $this->censoredVariableNames, true)) {
$value = $this->censorString;
}
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);
if ($hasCensorList && in_array($name, $this->censoredVariableNames, true)) {
$value = $this->censorString;
} else {
$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;
}
$data = [
'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,
'general' => [
'method' => Yii::$app->getRequest()->getMethod(),
'isAjax' => Yii::$app->getRequest()->getIsAjax(),
'isPjax' => Yii::$app->getRequest()->getIsPjax(),
'isFlash' => Yii::$app->getRequest()->getIsFlash(),
'isSecureConnection' => Yii::$app->getRequest()->getIsSecureConnection(),
],
'requestBody' => Yii::$app->getRequest()->getRawBody() == '' ? [] : [
'Content Type' => Yii::$app->getRequest()->getContentType(),
'Raw' => Yii::$app->getRequest()->getRawBody(),
'Decoded' => Yii::$app->getRequest()->getBodyParams(),
],
];
foreach ($this->displayVars as $name) {
$data[trim($name, '_')] = empty($GLOBALS[$name]) ? [] : $GLOBALS[$name];
}
return $this->censorArray($data);
}
Defined in: yii\debug\Panel::setError()
public void setError ( yii\debug\FlattenException $error ) | ||
$error | yii\debug\FlattenException |
public function setError(FlattenException $error)
{
$this->error = $error;
}