Skip to content

Commit ec7d1ae

Browse files
authored
Remove xdebug replacements on previews (php-debugbar#542)
1 parent 1b14192 commit ec7d1ae

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/DebugBar/DataCollector/DataCollector.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,32 @@ public function getDataFormatter()
7474
return $this->dataFormater;
7575
}
7676

77+
/**
78+
* Shorten the file path by removing the xdebug path replacements
79+
*
80+
* @param string $file
81+
* @return string
82+
*/
83+
public function normalizeFilePath($file)
84+
{
85+
if (empty($file)) {
86+
return '';
87+
}
88+
89+
if (file_exists($file)) {
90+
$file = realpath($file);
91+
}
92+
93+
foreach (array_keys($this->xdebugReplacements) as $path) {
94+
if (strpos($file, $path) === 0) {
95+
$file = substr($file, strlen($path));
96+
break;
97+
}
98+
}
99+
100+
return ltrim(str_replace('\\', '/', $file), '/');
101+
}
102+
77103
/**
78104
* Get an Xdebug Link to a file
79105
*

src/DebugBar/DataCollector/ExceptionsCollector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public function formatThrowableData($e)
139139
'type' => get_class($e),
140140
'message' => $e->getMessage(),
141141
'code' => $e->getCode(),
142-
'file' => $filePath,
142+
'file' => $this->normalizeFilePath($filePath),
143143
'line' => $e->getLine(),
144144
'stack_trace' => $e->getTraceAsString(),
145145
'stack_trace_html' => $traceHtml,

0 commit comments

Comments
 (0)