1
0
mirror of https://github.com/maximebf/php-debugbar.git synced 2025-07-12 12:26:29 +02: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
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 $exceptions = array();
protected $chainExceptions = false; 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 * Adds an exception to be profiled in the debug bar
* *
@ -65,6 +69,30 @@ class ExceptionsCollector extends DataCollector implements Renderable
return $this->exceptions; 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() public function collect()
{ {
return array( return array(
@ -102,6 +130,11 @@ class ExceptionsCollector extends DataCollector implements Renderable
$lines = array("Cannot open the file ($filePath) in which the exception occurred "); $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( return array(
'type' => get_class($e), 'type' => get_class($e),
'message' => $e->getMessage(), 'message' => $e->getMessage(),
@ -109,6 +142,7 @@ class ExceptionsCollector extends DataCollector implements Renderable
'file' => $filePath, 'file' => $filePath,
'line' => $e->getLine(), 'line' => $e->getLine(),
'stack_trace' => $e->getTraceAsString(), 'stack_trace' => $e->getTraceAsString(),
'stack_trace_html' => $traceHtml,
'surrounding_lines' => $lines, 'surrounding_lines' => $lines,
'xdebug_link' => $this->getXdebugLink($filePath, $e->getLine()) '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 * An extension of KVListWidget where the data represents a list
* of variables * of variables
* *
* Options: * Options:
* - data * - data
*/ */
@ -468,7 +468,7 @@ if (typeof(PhpDebugBar) == 'undefined') {
m.appendTo(li); m.appendTo(li);
this.$el.append(li); this.$el.append(li);
if (measure.params && !$.isEmptyObject(measure.params)) { if (measure.params && !$.isEmptyObject(measure.params)) {
var table = $('<table><tr><th colspan="2">Params</th></tr></table>').addClass(csscls('params')).appendTo(li); var table = $('<table><tr><th colspan="2">Params</th></tr></table>').addClass(csscls('params')).appendTo(li);
for (var key in measure.params) { for (var key in measure.params) {
@ -518,7 +518,7 @@ if (typeof(PhpDebugBar) == 'undefined') {
}); });
// ------------------------------------------------------------------ // ------------------------------------------------------------------
/** /**
* Widget for the displaying exceptions * Widget for the displaying exceptions
* *
@ -550,20 +550,26 @@ if (typeof(PhpDebugBar) == 'undefined') {
} }
if (e.surrounding_lines) { if (e.surrounding_lines) {
var pre = createCodeBlock(e.surrounding_lines.join(""), 'php').addClass(csscls('file')).appendTo(li); var pre = createCodeBlock(e.surrounding_lines.join(""), 'php').addClass(csscls('file')).appendTo(li);
li.click(function() { if (!e.stack_trace_html) {
if (pre.is(':visible')) { // This click event makes the var-dumper hard to use.
pre.hide(); li.click(function () {
} else { if (pre.is(':visible')) {
pre.show(); pre.hide();
} } else {
}); pre.show();
}
});
}
} }
if (e.stack_trace) { if (e.stack_trace_html) {
e.stack_trace.split("\n").forEach(function(trace) { var $trace = $('<span />').addClass(csscls('filename')).html(e.stack_trace_html);
var $traceLine = $('<div />'); $trace.appendTo(li);
$('<span />').addClass(csscls('filename')).text(trace).appendTo($traceLine); } else if (e.stack_trace) {
$traceLine.appendTo(li); 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); this.$list.$el.appendTo(this.$el);
@ -578,6 +584,6 @@ if (typeof(PhpDebugBar) == 'undefined') {
} }
}); });
})(PhpDebugBar.$); })(PhpDebugBar.$);