11
11
12
12
namespace Symfony \Bundle \FrameworkBundle \Templating \Helper ;
13
13
14
+ use Symfony \Component \HttpKernel \Debug \FileLinkFormatter ;
14
15
use Symfony \Component \Templating \Helper \Helper ;
15
16
16
17
/**
@@ -27,18 +28,13 @@ class CodeHelper extends Helper
27
28
/**
28
29
* Constructor.
29
30
*
30
- * @param string|array $fileLinkFormat The format for links to source files
31
- * @param string $rootDir The project root directory
32
- * @param string $charset The charset
31
+ * @param string|FileLinkFormatter $fileLinkFormat The format for links to source files
32
+ * @param string $rootDir The project root directory
33
+ * @param string $charset The charset
33
34
*/
34
35
public function __construct ($ fileLinkFormat , $ rootDir , $ charset )
35
36
{
36
- $ fileLinkFormat = $ fileLinkFormat ?: ini_get ('xdebug.file_link_format ' ) ?: get_cfg_var ('xdebug.file_link_format ' );
37
- if ($ fileLinkFormat && !is_array ($ fileLinkFormat )) {
38
- $ i = strpos ($ f = $ fileLinkFormat , '& ' , max (strrpos ($ f , '%f ' ), strrpos ($ f , '%l ' ))) ?: strlen ($ f );
39
- $ fileLinkFormat = array (substr ($ f , 0 , $ i )) + preg_split ('/&([^>]++)>/ ' , substr ($ f , $ i ), -1 , PREG_SPLIT_DELIM_CAPTURE );
40
- }
41
- $ this ->fileLinkFormat = $ fileLinkFormat ;
37
+ $ this ->fileLinkFormat = $ fileLinkFormat ?: ini_get ('xdebug.file_link_format ' ) ?: get_cfg_var ('xdebug.file_link_format ' );
42
38
$ this ->rootDir = str_replace ('\\' , '/ ' , $ rootDir ).'/ ' ;
43
39
$ this ->charset = $ charset ;
44
40
}
@@ -190,15 +186,8 @@ public function formatFile($file, $line, $text = null)
190
186
*/
191
187
public function getFileLink ($ file , $ line )
192
188
{
193
- if ($ this ->fileLinkFormat && is_file ($ file )) {
194
- for ($ i = 1 ; isset ($ this ->fileLinkFormat [$ i ]); ++$ i ) {
195
- if (0 === strpos ($ file , $ k = $ this ->fileLinkFormat [$ i ++])) {
196
- $ file = substr_replace ($ path , $ this ->fileLinkFormat [$ i ], 0 , strlen ($ k ));
197
- break ;
198
- }
199
- }
200
-
201
- return strtr ($ this ->fileLinkFormat [0 ], array ('%f ' => $ file , '%l ' => $ line ));
189
+ if ($ fmt = $ this ->fileLinkFormat ) {
190
+ return is_string ($ fmt ) ? strtr ($ fmt , array ('%f ' => $ file , '%l ' => $ line )) : $ fmt ->format ($ file , $ line );
202
191
}
203
192
204
193
return false ;
0 commit comments