|
23 | 23 | class CodeExtension extends AbstractExtension
|
24 | 24 | {
|
25 | 25 | private $fileLinkFormat;
|
26 |
| - private $rootDir; |
27 | 26 | private $charset;
|
28 | 27 | private $projectDir;
|
29 | 28 |
|
30 | 29 | /**
|
31 | 30 | * @param string|FileLinkFormatter $fileLinkFormat The format for links to source files
|
32 |
| - * @param string $rootDir The project root directory |
| 31 | + * @param string $projectDir The project directory |
33 | 32 | * @param string $charset The charset
|
34 | 33 | */
|
35 |
| - public function __construct($fileLinkFormat, string $rootDir, string $charset, string $projectDir = null) |
| 34 | + public function __construct($fileLinkFormat, string $projectDir, string $charset) |
36 | 35 | {
|
37 | 36 | $this->fileLinkFormat = $fileLinkFormat ?: ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format');
|
38 |
| - $this->rootDir = str_replace('/', \DIRECTORY_SEPARATOR, \dirname($rootDir)).\DIRECTORY_SEPARATOR; |
| 37 | + $this->projectDir = str_replace('\\', '/', $projectDir).'/'; |
39 | 38 | $this->charset = $charset;
|
40 |
| - $this->projectDir = $projectDir; |
41 | 39 | }
|
42 | 40 |
|
43 | 41 | /**
|
@@ -176,11 +174,10 @@ public function formatFile($file, $line, $text = null)
|
176 | 174 | $file = trim($file);
|
177 | 175 |
|
178 | 176 | if (null === $text) {
|
179 |
| - $text = str_replace('/', \DIRECTORY_SEPARATOR, $file); |
180 |
| - if (0 === strpos($text, $this->rootDir)) { |
181 |
| - $text = substr($text, \strlen($this->rootDir)); |
182 |
| - $text = explode(\DIRECTORY_SEPARATOR, $text, 2); |
183 |
| - $text = sprintf('<abbr title="%s%2$s">%s</abbr>%s', $this->rootDir, $text[0], isset($text[1]) ? \DIRECTORY_SEPARATOR.$text[1] : ''); |
| 177 | + $text = $file; |
| 178 | + if (null !== $rel = $this->getFileRelative($text)) { |
| 179 | + $rel = explode('/', $rel, 2); |
| 180 | + $text = sprintf('<abbr title="%s%2$s">%s</abbr>%s', $this->projectDir, $rel[0], '/'.($rel[1] ?? '')); |
184 | 181 | }
|
185 | 182 | }
|
186 | 183 |
|
@@ -214,8 +211,10 @@ public function getFileLink($file, $line)
|
214 | 211 |
|
215 | 212 | public function getFileRelative(string $file): ?string
|
216 | 213 | {
|
| 214 | + $file = str_replace('\\', '/', $file); |
| 215 | + |
217 | 216 | if (null !== $this->projectDir && 0 === strpos($file, $this->projectDir)) {
|
218 |
| - return ltrim(substr($file, \strlen($this->projectDir)), \DIRECTORY_SEPARATOR); |
| 217 | + return ltrim(substr($file, \strlen($this->projectDir)), '/'); |
219 | 218 | }
|
220 | 219 |
|
221 | 220 | return null;
|
|
0 commit comments