Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0928dcf

Browse files
committed
Move IDE file link formats from FrameworkExtension to FileLinkFormatter
1 parent 8679945 commit 0928dcf

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -213,20 +213,11 @@ public function load(array $configs, ContainerBuilder $container)
213213

214214
if (!$container->hasParameter('debug.file_link_format')) {
215215
if (!$container->hasParameter('templating.helper.code.file_link_format')) {
216-
$links = [
217-
'textmate' => 'txmt://open?url=file://%%f&line=%%l',
218-
'macvim' => 'mvim://open?url=file://%%f&line=%%l',
219-
'emacs' => 'emacs://open?url=file://%%f&line=%%l',
220-
'sublime' => 'subl://open?url=file://%%f&line=%%l',
221-
'phpstorm' => 'phpstorm://open?file=%%f&line=%%l',
222-
'atom' => 'atom://core/open/file?filename=%%f&line=%%l',
223-
'vscode' => 'vscode://file/%%f:%%l',
224-
];
225216
$ide = $config['ide'];
226217
// mark any env vars found in the ide setting as used
227218
$container->resolveEnvPlaceholders($ide);
228219

229-
$container->setParameter('templating.helper.code.file_link_format', str_replace('%', '%%', ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format')) ?: ($links[$ide] ?? $ide));
220+
$container->setParameter('templating.helper.code.file_link_format', str_replace('%', '%%', ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format')) ?: $ide);
230221
}
231222
$container->setParameter('debug.file_link_format', '%templating.helper.code.file_link_format%');
232223
}

src/Symfony/Component/HttpKernel/Debug/FileLinkFormatter.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@
2424
*/
2525
class FileLinkFormatter
2626
{
27+
private const FORMATS = [
28+
'textmate' => 'txmt://open?url=file://%f&line=%l',
29+
'macvim' => 'mvim://open?url=file://%f&line=%l',
30+
'emacs' => 'emacs://open?url=file://%f&line=%l',
31+
'sublime' => 'subl://open?url=file://%f&line=%l',
32+
'phpstorm' => 'phpstorm://open?file=%f&line=%l',
33+
'atom' => 'atom://core/open/file?filename=%f&line=%l',
34+
'vscode' => 'vscode://file/%f:%l',
35+
];
36+
2737
private $fileLinkFormat;
2838
private $requestStack;
2939
private $baseDir;
@@ -34,7 +44,7 @@ class FileLinkFormatter
3444
*/
3545
public function __construct($fileLinkFormat = null, RequestStack $requestStack = null, string $baseDir = null, $urlFormat = null)
3646
{
37-
$fileLinkFormat = $fileLinkFormat ?: ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format');
47+
$fileLinkFormat = (self::FORMATS[$fileLinkFormat] ?? $fileLinkFormat) ?: ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format');
3848
if ($fileLinkFormat && !\is_array($fileLinkFormat)) {
3949
$i = strpos($f = $fileLinkFormat, '&', max(strrpos($f, '%f'), strrpos($f, '%l'))) ?: \strlen($f);
4050
$fileLinkFormat = [substr($f, 0, $i)] + preg_split('/&([^>]++)>/', substr($f, $i), -1, \PREG_SPLIT_DELIM_CAPTURE);

src/Symfony/Component/HttpKernel/Tests/Debug/FileLinkFormatterTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,13 @@ public function testWhenNoFileLinkFormatAndRequest()
5151

5252
$this->assertSame('http://www.example.org/_profiler/open?file=file.php&line=3#line3', $sut->format($file, 3));
5353
}
54+
55+
public function testIdeFileLinkFormat()
56+
{
57+
$file = __DIR__.\DIRECTORY_SEPARATOR.'file.php';
58+
59+
$sut = new FileLinkFormatter('atom');
60+
61+
$this->assertSame("atom://core/open/file?filename=$file&line=3", $sut->format($file, 3));
62+
}
5463
}

0 commit comments

Comments
 (0)