mirror of
https://github.com/maximebf/php-debugbar.git
synced 2025-07-16 14:26:38 +02:00
normalize file paths on exceptions traces (#566)
* normalize file paths on exceptions traces * avoid trace string when there is trace html * normalize file path on message `cannot open the file` * fix
This commit is contained in:
@ -92,6 +92,16 @@ class ExceptionsCollector extends DataCollector implements Renderable
|
|||||||
*/
|
*/
|
||||||
public function formatTrace(array $trace)
|
public function formatTrace(array $trace)
|
||||||
{
|
{
|
||||||
|
if (! empty($this->xdebugReplacements)) {
|
||||||
|
$trace = array_map(function ($track) {
|
||||||
|
if (isset($track['file'])) {
|
||||||
|
$track['file'] = $this->normalizeFilePath($track['file']);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $track;
|
||||||
|
}, $trace);
|
||||||
|
}
|
||||||
|
|
||||||
return $trace;
|
return $trace;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -103,8 +113,20 @@ class ExceptionsCollector extends DataCollector implements Renderable
|
|||||||
*/
|
*/
|
||||||
public function formatTraceAsString($e)
|
public function formatTraceAsString($e)
|
||||||
{
|
{
|
||||||
|
if (! empty($this->xdebugReplacements)) {
|
||||||
|
return implode("\n", array_map(function ($track) {
|
||||||
|
$track = explode(' ', $track);
|
||||||
|
if (isset($track[1])) {
|
||||||
|
$track[1] = $this->normalizeFilePath($track[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return implode(' ', $track);
|
||||||
|
}, explode("\n", $e->getTraceAsString())));
|
||||||
|
}
|
||||||
|
|
||||||
return $e->getTraceAsString();
|
return $e->getTraceAsString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns Throwable data as an array
|
* Returns Throwable data as an array
|
||||||
*
|
*
|
||||||
@ -119,7 +141,7 @@ class ExceptionsCollector extends DataCollector implements Renderable
|
|||||||
$start = $e->getLine() - 4;
|
$start = $e->getLine() - 4;
|
||||||
$lines = array_slice($lines, $start < 0 ? 0 : $start, 7);
|
$lines = array_slice($lines, $start < 0 ? 0 : $start, 7);
|
||||||
} else {
|
} else {
|
||||||
$lines = array("Cannot open the file ($filePath) in which the exception occurred ");
|
$lines = array('Cannot open the file ('.$this->normalizeFilePath($filePath).') in which the exception occurred');
|
||||||
}
|
}
|
||||||
|
|
||||||
$traceHtml = null;
|
$traceHtml = null;
|
||||||
@ -133,7 +155,7 @@ class ExceptionsCollector extends DataCollector implements Renderable
|
|||||||
'code' => $e->getCode(),
|
'code' => $e->getCode(),
|
||||||
'file' => $this->normalizeFilePath($filePath),
|
'file' => $this->normalizeFilePath($filePath),
|
||||||
'line' => $e->getLine(),
|
'line' => $e->getLine(),
|
||||||
'stack_trace' => $this->formatTraceAsString($e),
|
'stack_trace' => $traceHtml ? null : $this->formatTraceAsString($e),
|
||||||
'stack_trace_html' => $traceHtml,
|
'stack_trace_html' => $traceHtml,
|
||||||
'surrounding_lines' => $lines,
|
'surrounding_lines' => $lines,
|
||||||
'xdebug_link' => $this->getXdebugLink($filePath, $e->getLine())
|
'xdebug_link' => $this->getXdebugLink($filePath, $e->getLine())
|
||||||
|
Reference in New Issue
Block a user