@@ -37,9 +37,16 @@ class ExceptionHandler
37
37
38
38
public function __construct ($ debug = true , $ charset = null , $ fileLinkFormat = null )
39
39
{
40
+ $ fileLinkFormat = $ fileLinkFormat ?: ini_get ('xdebug.file_link_format ' ) ?: get_cfg_var ('xdebug.file_link_format ' );
41
+ if ($ fileLinkFormat && !is_array ($ fileLinkFormat )) {
42
+ $ i = max (strpos ($ fileLinkFormat , '%f ' ), strpos ($ fileLinkFormat , '%l ' ));
43
+ $ i = strpos ($ fileLinkFormat , '# ' , $ i ) ?: strlen ($ fileLinkFormat );
44
+ $ fileLinkFormat = array (substr ($ fileLinkFormat , 0 , $ i ), substr ($ fileLinkFormat , $ i + 1 ));
45
+ parse_str ($ fileLinkFormat [1 ], $ fileLinkFormat [1 ]);
46
+ }
40
47
$ this ->debug = $ debug ;
41
48
$ this ->charset = $ charset ?: ini_get ('default_charset ' ) ?: 'UTF-8 ' ;
42
- $ this ->fileLinkFormat = $ fileLinkFormat ?: ini_get ( ' xdebug.file_link_format ' ) ?: get_cfg_var ( ' xdebug.file_link_format ' ) ;
49
+ $ this ->fileLinkFormat = $ fileLinkFormat ;
43
50
}
44
51
45
52
/**
@@ -82,14 +89,22 @@ public function setHandler(callable $handler = null)
82
89
/**
83
90
* Sets the format for links to source files.
84
91
*
85
- * @param string $format The format for links to source files
92
+ * @param string|array $format The format for links to source files
86
93
*
87
94
* @return string The previous file link format
88
95
*/
89
- public function setFileLinkFormat ($ format )
96
+ public function setFileLinkFormat ($ fileLinkFormat )
90
97
{
91
98
$ old = $ this ->fileLinkFormat ;
92
- $ this ->fileLinkFormat = $ format ;
99
+ if ($ fileLinkFormat && !is_array ($ fileLinkFormat )) {
100
+ $ i = strpos ($ fileLinkFormat , '# ' ) ?: strlen ($ fileLinkFormat );
101
+ $ fileLinkFormat = array (substr ($ fileLinkFormat , 0 , $ i ), substr ($ fileLinkFormat , $ i + 1 ));
102
+ parse_str ($ fileLinkFormat [1 ], $ fileLinkFormat [1 ]);
103
+ }
104
+ $ this ->fileLinkFormat = $ fileLinkFormat ;
105
+ if ($ old ) {
106
+ $ old = $ old [0 ].($ old [1 ] ? '# ' .http_build_query ($ old [1 ], '' , '& ' ) : '' );
107
+ }
93
108
94
109
return $ old ;
95
110
}
@@ -350,16 +365,21 @@ private function formatClass($class)
350
365
351
366
private function formatPath ($ path , $ line )
352
367
{
353
- $ path = $ this ->escapeHtml ($ path );
354
- $ file = preg_match ('#[^/ \\\\]*$# ' , $ path , $ file ) ? $ file [0 ] : $ path ;
368
+ $ file = $ this ->escapeHtml (preg_match ('#[^/ \\\\]*+$# ' , $ path , $ file ) ? $ file [0 ] : $ path );
355
369
356
- if ($ linkFormat = $ this ->fileLinkFormat ) {
357
- $ link = strtr ($ this ->escapeHtml ($ linkFormat ), array ('%f ' => $ path , '%l ' => (int ) $ line ));
370
+ if ($ fileLinkFormat = $ this ->fileLinkFormat ) {
371
+ foreach ($ fileLinkFormat [1 ] as $ k => $ v ) {
372
+ if (0 === strpos ($ path , $ k )) {
373
+ $ path = substr_replace ($ path , $ v , 0 , strlen ($ k ));
374
+ break ;
375
+ }
376
+ }
377
+ $ link = strtr ($ fileLinkFormat [0 ], array ('%f ' => $ path , '%l ' => (int ) $ line ));
358
378
359
- return sprintf (' in <a href="%s" title="Go to source">%s line %d</a> ' , $ link , $ file , $ line );
379
+ return sprintf (' in <a href="%s" title="Go to source">%s line %d</a> ' , $ this -> escapeHtml ( $ link) , $ file , $ line );
360
380
}
361
381
362
- return sprintf (' in <a title="%s line %3$d">%s line %d</a> ' , $ path , $ file , $ line );
382
+ return sprintf (' in <a title="%s line %3$d">%s line %d</a> ' , $ this -> escapeHtml ( $ path) , $ file , $ line );
363
383
}
364
384
365
385
/**
0 commit comments