1111
1212namespace Symfony \Bundle \FrameworkBundle \Templating \Helper ;
1313
14+ use Symfony \Component \HttpKernel \Debug \FileLinkFormatter ;
1415use Symfony \Component \Templating \Helper \Helper ;
1516
1617/**
@@ -27,18 +28,13 @@ class CodeHelper extends Helper
2728 /**
2829 * Constructor.
2930 *
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
3334 */
3435 public function __construct ($ fileLinkFormat , $ rootDir , $ charset )
3536 {
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 ' );
4238 $ this ->rootDir = str_replace ('\\' , '/ ' , $ rootDir ).'/ ' ;
4339 $ this ->charset = $ charset ;
4440 }
@@ -190,15 +186,8 @@ public function formatFile($file, $line, $text = null)
190186 */
191187 public function getFileLink ($ file , $ line )
192188 {
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 );
202191 }
203192
204193 return false ;
0 commit comments