Class yii\debug\panels\DumpPanel

Inheritanceyii\debug\panels\DumpPanel » yii\debug\Panel » yii\base\Component
Available since extension's version2.1.0
Source Code https://github.com/yiisoft/yii2-debug/blob/master/src/panels/DumpPanel.php

Dump panel that collects and displays debug messages (Logger::LEVEL_TRACE).

Public Properties

Hide inherited properties

Property Type Description Defined By
$actions array Array of actions to add to the debug modules default controller. yii\debug\Panel
$categories array The message categories to filter by. yii\debug\panels\DumpPanel
$data mixed Data associated with panel yii\debug\Panel
$depth integer Maximum depth that the dumper should go into the variable yii\debug\panels\DumpPanel
$detail string Content that is displayed in debugger detail view. yii\debug\Panel
$error yii\debug\FlattenException|null Error while saving the panel yii\debug\Panel
$highlight boolean Whether the result should be syntax-highlighted yii\debug\panels\DumpPanel
$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
$varDumpCallback callable Callback that replaces the built-in var dumper. yii\debug\panels\DumpPanel

Protected Properties

Hide inherited properties

Property Type Description Defined By

Public Methods

Hide inherited methods

Method Description Defined By
getDetail() yii\debug\panels\DumpPanel
getError() yii\debug\Panel
getName() yii\debug\panels\DumpPanel
getSummary() yii\debug\panels\DumpPanel
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\DumpPanel
setError() yii\debug\Panel
varDump() Called by save() to format the dumped variable. yii\debug\panels\DumpPanel

Protected Methods

Hide inherited methods

Method Description Defined By
getLogMessages() Gets messages from log target and filters according to their categories and levels. yii\debug\Panel
getModels() Returns an array of models that represents logs of the current request. yii\debug\panels\DumpPanel

Property Details

Hide inherited properties

$categories public property

The message categories to filter by. If empty array, it means all categories are allowed

public array $categories = [
    
'application',
]
$depth public property

Maximum depth that the dumper should go into the variable

public integer $depth 10
$highlight public property

Whether the result should be syntax-highlighted

public boolean $highlight true
$varDumpCallback public property (available since version 2.1.3)

Callback that replaces the built-in var dumper. The signature of this function should be: function (mixed $data, DumpPanel $panel)

public callable $varDumpCallback null

Method Details

Hide inherited methods

getDetail() public method

public string getDetail ( )
return string

Content that is displayed in debugger detail view

                public function getDetail()
{
    $searchModel = new Log();
    $dataProvider = $searchModel->search(Yii::$app->request->getQueryParams(), $this->getModels());
    return Yii::$app->view->render('panels/dump/detail', [
                'dataProvider' => $dataProvider,
                'panel' => $this,
                'searchModel' => $searchModel,
    ]);
}

            
getError() public method (available since version 2.0.10)
public yii\debug\FlattenException|null getError ( )

                public function getError()
{
    return $this->error;
}

            
getLogMessages() protected method (available since version 2.1.4)

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;
}

            
getModels() protected method

Returns an array of models that represents logs of the current request.

Can be used with data providers, such as \yii\data\ArrayDataProvider.

protected array getModels ( $refresh false )
$refresh boolean

If need to build models from log messages and refresh them.

return array

Models

                protected function getModels($refresh = false)
{
    if ($this->_models === null || $refresh) {
        $this->_models = [];
        foreach ($this->data as $message) {
            $this->_models[] = [
                'message' => $message[0],
                'level' => $message[1],
                'category' => $message[2],
                'time' => $message[3] * 1000, // time in milliseconds
                'trace' => $message[4]
            ];
        }
    }
    return $this->_models;
}

            
getName() public method

public string getName ( )
return string

Name of the panel

                public function getName()
{
    return 'Dump';
}

            
getSummary() public method

public string getSummary ( )
return string

Content that is displayed at debug toolbar

                public function getSummary()
{
    return Yii::$app->view->render('panels/dump/summary', ['panel' => $this]);
}

            
getTraceLine() public method (available since version 2.0.7)

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 an internal PHP function, such as `call_user_func`, in the backtrace, the 'file' and 'line' not be available.
     * @see https://www.php.net/manual/en/function.debug-backtrace.php#59713
     */
    if (!isset($options['file'])) {
        return VarDumper::dumpAsString($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']]);
}

            
getUrl() public method
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);
}

            
hasError() public method (available since version 2.0.10)
public boolean hasError ( )

                public function hasError()
{
    return $this->error !== null;
}

            
isEnabled() public method (available since version 2.0.10)

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;
}

            
load() public method

Defined in: yii\debug\Panel::load()

Loads data into the panel

public void load ( $data )
$data mixed

                public function load($data)
{
    $this->data = $data;
}

            
save() public method

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()
{
    $except = [];
    if (isset($this->module->panels['router'])) {
        $except = $this->module->panels['router']->getCategories();
    }
    $messages = $this->getLogMessages(Logger::LEVEL_TRACE, $this->categories, $except);
    foreach ($messages as &$message) {
        if (!isset($message[0])) {
            continue;
        }
        $message[0] = $this->varDump($message[0]);
    }
    return $messages;
}

            
setError() public method (available since version 2.0.10)
public void setError ( yii\debug\FlattenException $error )
$error yii\debug\FlattenException

                public function setError(FlattenException $error)
{
    $this->error = $error;
}

            
varDump() public method (available since version 2.1.3)

Called by save() to format the dumped variable.

public void varDump ( $var )
$var

                public function varDump($var)
{
    if (is_callable($this->varDumpCallback)) {
        return call_user_func($this->varDumpCallback, $var, $this);
    }
    $message = VarDumper::dumpAsString($var, $this->depth, $this->highlight);
    //don't encode highlighted variables
    if (!$this->highlight) {
        $message = Html::encode($message);
    }
    return $message;
}