Skip to content

Commit 70097c2

Browse files
jeremyFreeAgentnicolas-grekas
authored andcommitted
Added a default ide file link web view
1 parent 02ea160 commit 70097c2

File tree

3 files changed

+13
-20
lines changed

3 files changed

+13
-20
lines changed

Resources/config/debug_prod.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,14 @@
1717
<argument>-1</argument><!-- Log levels map for enabled error levels -->
1818
<argument>%debug.error_handler.throw_at%</argument>
1919
<argument>true</argument>
20-
<argument>%debug.file_link_format%</argument>
20+
<argument type="service" id="debug.file_link_formatter"></argument>
2121
<argument>true</argument>
2222
</service>
2323

2424
<service id="debug.stopwatch" class="Symfony\Component\Stopwatch\Stopwatch" />
25+
26+
<service id="debug.file_link_formatter" class="Symfony\Component\HttpKernel\Debug\FileLinkFormatter" public="false">
27+
<argument>%debug.file_link_format%</argument>
28+
</service>
2529
</services>
2630
</container>

Resources/config/templating_php.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444

4545
<service id="templating.helper.code" class="Symfony\Bundle\FrameworkBundle\Templating\Helper\CodeHelper">
4646
<tag name="templating.helper" alias="code" />
47-
<argument>%debug.file_link_format%</argument>
47+
<argument type="service" id="debug.file_link_formatter"></argument>
4848
<argument>%kernel.root_dir%</argument>
4949
<argument>%kernel.charset%</argument>
5050
</service>

Templating/Helper/CodeHelper.php

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\Templating\Helper;
1313

14+
use Symfony\Component\HttpKernel\Debug\FileLinkFormatter;
1415
use 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

Comments
 (0)