1
0
mirror of https://github.com/maximebf/php-debugbar.git synced 2025-01-16 21:08:34 +01: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:
angeljqv 2024-02-10 05:03:26 -05:00 committed by GitHub
parent 429b6f7edc
commit 87f04a2762
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -92,6 +92,16 @@ class ExceptionsCollector extends DataCollector implements Renderable
*/
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;
}
@ -103,8 +113,20 @@ class ExceptionsCollector extends DataCollector implements Renderable
*/
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();
}
/**
* Returns Throwable data as an array
*
@ -119,7 +141,7 @@ class ExceptionsCollector extends DataCollector implements Renderable
$start = $e->getLine() - 4;
$lines = array_slice($lines, $start < 0 ? 0 : $start, 7);
} 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;
@ -133,7 +155,7 @@ class ExceptionsCollector extends DataCollector implements Renderable
'code' => $e->getCode(),
'file' => $this->normalizeFilePath($filePath),
'line' => $e->getLine(),
'stack_trace' => $this->formatTraceAsString($e),
'stack_trace' => $traceHtml ? null : $this->formatTraceAsString($e),
'stack_trace_html' => $traceHtml,
'surrounding_lines' => $lines,
'xdebug_link' => $this->getXdebugLink($filePath, $e->getLine())