Skip to content

Commit eed7a9c

Browse files
committed
feature #48379 [HttpKernel] Set a default file link format when none is provided to FileLinkFormatter (alexandre-daubois)
This PR was merged into the 6.3 branch. Discussion ---------- [HttpKernel] Set a default file link format when none is provided to FileLinkFormatter | Q | A | ------------- | --- | Branch? | 6.3 | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | _N/A_ | License | MIT | Doc PR | _N/A_ This change allow commands like `debug:route` to have clickable links. ![image](https://user-images.githubusercontent.com/2144837/204470917-0df8aeca-f71f-49b8-8f6b-57dbd2b7ed32.png) Link pointed by controller's action: `file:///home/alexandredaubois/PhpstormProjects/dummy_project/src/Controller/SomeController.php#L13` Commits ------- 269f4f1 [HttpKernel] Set a default file link format when none is provided to FileLinkFormatter
2 parents 8fa4800 + 269f4f1 commit eed7a9c

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class FileLinkFormatter
3535
*/
3636
public function __construct(string|array $fileLinkFormat = null, RequestStack $requestStack = null, string $baseDir = null, string|\Closure $urlFormat = null)
3737
{
38-
$fileLinkFormat ??= $_SERVER['SYMFONY_IDE'] ?? '';
38+
$fileLinkFormat ??= $_SERVER['SYMFONY_IDE'] ?? 'file://%f#L%l';
3939
if (!\is_array($fileLinkFormat) && $fileLinkFormat = (ErrorRendererInterface::IDE_LINK_FORMATS[$fileLinkFormat] ?? $fileLinkFormat) ?: \ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format') ?: false) {
4040
$i = strpos($f = $fileLinkFormat, '&', max(strrpos($f, '%f'), strrpos($f, '%l'))) ?: \strlen($f);
4141
$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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function testAfterUnserialize()
2929
{
3030
$sut = unserialize(serialize(new FileLinkFormatter()));
3131

32-
$this->assertFalse($sut->format('/kernel/root/src/my/very/best/file.php', 3));
32+
$this->assertSame('file:///kernel/root/src/my/very/best/file.php#L3', $sut->format('/kernel/root/src/my/very/best/file.php', 3));
3333
}
3434

3535
public function testWhenFileLinkFormatAndNoRequest()

0 commit comments

Comments
 (0)