From 42a27b27705a1176bcfb5ff18ce9d92d3f8e5b41 Mon Sep 17 00:00:00 2001 From: MatTheCat Date: Fri, 30 Apr 2021 14:55:51 +0200 Subject: [PATCH] Move IDE file link formats from FrameworkExtension to FileLinkFormatter --- .../DependencyInjection/FrameworkExtension.php | 15 +-------------- .../HttpKernel/Debug/FileLinkFormatter.php | 12 +++++++++++- .../Tests/Debug/FileLinkFormatterTest.php | 9 +++++++++ 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index a9b1698ce0..c7d3b7e191 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -294,20 +294,7 @@ class FrameworkExtension extends Extension } if (!$container->hasParameter('debug.file_link_format')) { - $links = [ - 'textmate' => 'txmt://open?url=file://%%f&line=%%l', - 'macvim' => 'mvim://open?url=file://%%f&line=%%l', - 'emacs' => 'emacs://open?url=file://%%f&line=%%l', - 'sublime' => 'subl://open?url=file://%%f&line=%%l', - 'phpstorm' => 'phpstorm://open?file=%%f&line=%%l', - 'atom' => 'atom://core/open/file?filename=%%f&line=%%l', - 'vscode' => 'vscode://file/%%f:%%l', - ]; - $ide = $config['ide']; - // mark any env vars found in the ide setting as used - $container->resolveEnvPlaceholders($ide); - - $container->setParameter('debug.file_link_format', str_replace('%', '%%', ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format')) ?: ($links[$ide] ?? $ide)); + $container->setParameter('debug.file_link_format', $config['ide']); } if (!empty($config['test'])) { diff --git a/src/Symfony/Component/HttpKernel/Debug/FileLinkFormatter.php b/src/Symfony/Component/HttpKernel/Debug/FileLinkFormatter.php index 55dcb52521..017409f194 100644 --- a/src/Symfony/Component/HttpKernel/Debug/FileLinkFormatter.php +++ b/src/Symfony/Component/HttpKernel/Debug/FileLinkFormatter.php @@ -24,6 +24,16 @@ use Symfony\Component\Routing\Generator\UrlGeneratorInterface; */ class FileLinkFormatter { + private const FORMATS = [ + 'textmate' => 'txmt://open?url=file://%f&line=%l', + 'macvim' => 'mvim://open?url=file://%f&line=%l', + 'emacs' => 'emacs://open?url=file://%f&line=%l', + 'sublime' => 'subl://open?url=file://%f&line=%l', + 'phpstorm' => 'phpstorm://open?file=%f&line=%l', + 'atom' => 'atom://core/open/file?filename=%f&line=%l', + 'vscode' => 'vscode://file/%f:%l', + ]; + private $fileLinkFormat; private $requestStack; private $baseDir; @@ -34,7 +44,7 @@ class FileLinkFormatter */ public function __construct($fileLinkFormat = null, RequestStack $requestStack = null, string $baseDir = null, $urlFormat = null) { - $fileLinkFormat = $fileLinkFormat ?: ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format'); + $fileLinkFormat = (self::FORMATS[$fileLinkFormat] ?? $fileLinkFormat) ?: ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format'); if ($fileLinkFormat && !\is_array($fileLinkFormat)) { $i = strpos($f = $fileLinkFormat, '&', max(strrpos($f, '%f'), strrpos($f, '%l'))) ?: \strlen($f); $fileLinkFormat = [substr($f, 0, $i)] + preg_split('/&([^>]++)>/', substr($f, $i), -1, \PREG_SPLIT_DELIM_CAPTURE); diff --git a/src/Symfony/Component/HttpKernel/Tests/Debug/FileLinkFormatterTest.php b/src/Symfony/Component/HttpKernel/Tests/Debug/FileLinkFormatterTest.php index 1f4d298bf3..af84d10eb3 100644 --- a/src/Symfony/Component/HttpKernel/Tests/Debug/FileLinkFormatterTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/Debug/FileLinkFormatterTest.php @@ -51,4 +51,13 @@ class FileLinkFormatterTest extends TestCase $this->assertSame('http://www.example.org/_profiler/open?file=file.php&line=3#line3', $sut->format($file, 3)); } + + public function testIdeFileLinkFormat() + { + $file = __DIR__.\DIRECTORY_SEPARATOR.'file.php'; + + $sut = new FileLinkFormatter('atom'); + + $this->assertSame("atom://core/open/file?filename=$file&line=3", $sut->format($file, 3)); + } }