1
0
mirror of https://github.com/maximebf/php-debugbar.git synced 2025-07-12 20:36:45 +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

@ -550,6 +550,8 @@ 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);
if (!e.stack_trace_html) {
// This click event makes the var-dumper hard to use.
li.click(function () { li.click(function () {
if (pre.is(':visible')) { if (pre.is(':visible')) {
pre.hide(); pre.hide();
@ -558,7 +560,11 @@ if (typeof(PhpDebugBar) == 'undefined') {
} }
}); });
} }
if (e.stack_trace) { }
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) { e.stack_trace.split("\n").forEach(function (trace) {
var $traceLine = $('<div />'); var $traceLine = $('<div />');
$('<span />').addClass(csscls('filename')).text(trace).appendTo($traceLine); $('<span />').addClass(csscls('filename')).text(trace).appendTo($traceLine);