1
0
mirror of https://github.com/maximebf/php-debugbar.git synced 2025-01-16 21:08:34 +01:00

Allow useHtmlVarDumper() on ExceptionsCollector (#464)

This commit is contained in:
Pierre Rudloff 2021-06-19 19:09:02 +02:00 committed by GitHub
parent 7602079356
commit 1a873d72e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 58 additions and 18 deletions

View File

@ -21,6 +21,10 @@ class ExceptionsCollector extends DataCollector implements Renderable
protected $exceptions = array();
protected $chainExceptions = false;
// The HTML var dumper requires debug bar users to support the new inline assets, which not all
// may support yet - so return false by default for now.
protected $useHtmlVarDumper = false;
/**
* Adds an exception to be profiled in the debug bar
*
@ -65,6 +69,30 @@ class ExceptionsCollector extends DataCollector implements Renderable
return $this->exceptions;
}
/**
* Sets a flag indicating whether the Symfony HtmlDumper will be used to dump variables for
* rich variable rendering.
*
* @param bool $value
* @return $this
*/
public function useHtmlVarDumper($value = true)
{
$this->useHtmlVarDumper = $value;
return $this;
}
/**
* Indicates whether the Symfony HtmlDumper will be used to dump variables for rich variable
* rendering.
*
* @return mixed
*/
public function isHtmlVarDumperUsed()
{
return $this->useHtmlVarDumper;
}
public function collect()
{
return array(
@ -102,6 +130,11 @@ class ExceptionsCollector extends DataCollector implements Renderable
$lines = array("Cannot open the file ($filePath) in which the exception occurred ");
}
$traceHtml = null;
if ($this->isHtmlVarDumperUsed()) {
$traceHtml = $this->getVarDumper()->renderVar($e->getTrace());
}
return array(
'type' => get_class($e),
'message' => $e->getMessage(),
@ -109,6 +142,7 @@ class ExceptionsCollector extends DataCollector implements Renderable
'file' => $filePath,
'line' => $e->getLine(),
'stack_trace' => $e->getTraceAsString(),
'stack_trace_html' => $traceHtml,
'surrounding_lines' => $lines,
'xdebug_link' => $this->getXdebugLink($filePath, $e->getLine())
);

View File

@ -216,11 +216,11 @@ if (typeof(PhpDebugBar) == 'undefined') {
});
// ------------------------------------------------------------------
/**
* An extension of KVListWidget where the data represents a list
* of variables
*
*
* Options:
* - data
*/
@ -468,7 +468,7 @@ if (typeof(PhpDebugBar) == 'undefined') {
m.appendTo(li);
this.$el.append(li);
if (measure.params && !$.isEmptyObject(measure.params)) {
var table = $('<table><tr><th colspan="2">Params</th></tr></table>').addClass(csscls('params')).appendTo(li);
for (var key in measure.params) {
@ -518,7 +518,7 @@ if (typeof(PhpDebugBar) == 'undefined') {
});
// ------------------------------------------------------------------
/**
* Widget for the displaying exceptions
*
@ -550,20 +550,26 @@ if (typeof(PhpDebugBar) == 'undefined') {
}
if (e.surrounding_lines) {
var pre = createCodeBlock(e.surrounding_lines.join(""), 'php').addClass(csscls('file')).appendTo(li);
li.click(function() {
if (pre.is(':visible')) {
pre.hide();
} else {
pre.show();
}
});
if (!e.stack_trace_html) {
// This click event makes the var-dumper hard to use.
li.click(function () {
if (pre.is(':visible')) {
pre.hide();
} else {
pre.show();
}
});
}
}
if (e.stack_trace) {
e.stack_trace.split("\n").forEach(function(trace) {
var $traceLine = $('<div />');
$('<span />').addClass(csscls('filename')).text(trace).appendTo($traceLine);
$traceLine.appendTo(li);
});
if (e.stack_trace_html) {
var $trace = $('<span />').addClass(csscls('filename')).html(e.stack_trace_html);
$trace.appendTo(li);
} else if (e.stack_trace) {
e.stack_trace.split("\n").forEach(function (trace) {
var $traceLine = $('<div />');
$('<span />').addClass(csscls('filename')).text(trace).appendTo($traceLine);
$traceLine.appendTo(li);
});
}
}});
this.$list.$el.appendTo(this.$el);
@ -578,6 +584,6 @@ if (typeof(PhpDebugBar) == 'undefined') {
}
});
})(PhpDebugBar.$);