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

Skip to content

Commit 42a27b2

Browse files
committed
Move IDE file link formats from FrameworkExtension to FileLinkFormatter
1 parent 8ff0a3e commit 42a27b2

File tree

3 files changed

+21
-15
lines changed

3 files changed

+21
-15
lines changed

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

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -294,20 +294,7 @@ public function load(array $configs, ContainerBuilder $container)
294294
}
295295

296296
if (!$container->hasParameter('debug.file_link_format')) {
297-
$links = [
298-
'textmate' => 'txmt://open?url=file://%%f&line=%%l',
299-
'macvim' => 'mvim://open?url=file://%%f&line=%%l',
300-
'emacs' => 'emacs://open?url=file://%%f&line=%%l',
301-
'sublime' => 'subl://open?url=file://%%f&line=%%l',
302-
'phpstorm' => 'phpstorm://open?file=%%f&line=%%l',
303-
'atom' => 'atom://core/open/file?filename=%%f&line=%%l',
304-
'vscode' => 'vscode://file/%%f:%%l',
305-
];
306-
$ide = $config['ide'];
307-
// mark any env vars found in the ide setting as used
308-
$container->resolveEnvPlaceholders($ide);
309-
310-
$container->setParameter('debug.file_link_format', str_replace('%', '%%', ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format')) ?: ($links[$ide] ?? $ide));
297+
$container->setParameter('debug.file_link_format', $config['ide']);
311298
}
312299

313300
if (!empty($config['test'])) {

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)