Skip to content

Commit 03ad4af

Browse files
committed
Read SYMFONY_IDE to render exception in case of fatal error
1 parent 9a29631 commit 03ad4af

File tree

5 files changed

+19
-13
lines changed

5 files changed

+19
-13
lines changed

src/Symfony/Component/ErrorHandler/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CHANGELOG
55
---
66

77
* Report overridden `@final` constants and properties
8+
* Read environment variable `SYMFONY_IDE` to configure file link format
89

910
5.4
1011
---

src/Symfony/Component/ErrorHandler/ErrorRenderer/ErrorRendererInterface.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@
2020
*/
2121
interface ErrorRendererInterface
2222
{
23+
public const IDE_LINK_FORMATS = [
24+
'textmate' => 'txmt://open?url=file://%f&line=%l',
25+
'macvim' => 'mvim://open?url=file://%f&line=%l',
26+
'emacs' => 'emacs://open?url=file://%f&line=%l',
27+
'sublime' => 'subl://open?url=file://%f&line=%l',
28+
'phpstorm' => 'phpstorm://open?file=%f&line=%l',
29+
'atom' => 'atom://core/open/file?filename=%f&line=%l',
30+
'vscode' => 'vscode://file/%f:%l',
31+
];
32+
2333
/**
2434
* Renders a Throwable as a FlattenException.
2535
*/

src/Symfony/Component/ErrorHandler/ErrorRenderer/HtmlErrorRenderer.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@ public function __construct(bool|callable $debug = false, string $charset = null
5050
{
5151
$this->debug = \is_bool($debug) ? $debug : $debug(...);
5252
$this->charset = $charset ?: (ini_get('default_charset') ?: 'UTF-8');
53-
$this->fileLinkFormat = $fileLinkFormat ?: (ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format'));
53+
$fileLinkFormat ??= $_SERVER['SYMFONY_IDE'] ?? null;
54+
$this->fileLinkFormat = is_string($fileLinkFormat)
55+
? (ErrorRendererInterface::IDE_LINK_FORMATS[$fileLinkFormat] ?? $fileLinkFormat ?: false)
56+
: ($fileLinkFormat ?: ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format') ?: false);
5457
$this->projectDir = $projectDir;
5558
$this->outputBuffer = \is_string($outputBuffer) ? $outputBuffer : $outputBuffer(...);
5659
$this->logger = $logger;

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

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

1212
namespace Symfony\Component\HttpKernel\Debug;
1313

14+
use Symfony\Component\ErrorHandler\ErrorRenderer\ErrorRendererInterface;
1415
use Symfony\Component\HttpFoundation\Request;
1516
use Symfony\Component\HttpFoundation\RequestStack;
1617
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
@@ -24,16 +25,6 @@
2425
*/
2526
class FileLinkFormatter
2627
{
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-
3728
private array|false $fileLinkFormat;
3829
private ?RequestStack $requestStack = null;
3930
private ?string $baseDir = null;
@@ -44,7 +35,8 @@ class FileLinkFormatter
4435
*/
4536
public function __construct(string $fileLinkFormat = null, RequestStack $requestStack = null, string $baseDir = null, string|\Closure $urlFormat = null)
4637
{
47-
$fileLinkFormat = (self::FORMATS[$fileLinkFormat] ?? $fileLinkFormat) ?: ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format') ?: false;
38+
$fileLinkFormat ??= $_SERVER['SYMFONY_IDE'] ?? null;
39+
$fileLinkFormat = (ErrorRendererInterface::IDE_LINK_FORMATS[$fileLinkFormat] ?? $fileLinkFormat) ?: ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format') ?: false;
4840
if ($fileLinkFormat && !\is_array($fileLinkFormat)) {
4941
$i = strpos($f = $fileLinkFormat, '&', max(strrpos($f, '%f'), strrpos($f, '%l'))) ?: \strlen($f);
5042
$fileLinkFormat = [substr($f, 0, $i)] + preg_split('/&([^>]++)>/', substr($f, $i), -1, \PREG_SPLIT_DELIM_CAPTURE);

src/Symfony/Component/HttpKernel/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
],
1818
"require": {
1919
"php": ">=8.1",
20-
"symfony/error-handler": "^5.4|^6.0",
20+
"symfony/error-handler": "^6.1",
2121
"symfony/event-dispatcher": "^5.4|^6.0",
2222
"symfony/http-foundation": "^5.4|^6.0",
2323
"symfony/polyfill-ctype": "^1.8",

0 commit comments

Comments
 (0)