Skip to content

Commit c942cfe

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

File tree

4 files changed

+19
-13
lines changed

4 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/HtmlErrorRenderer.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@
2323
*/
2424
class HtmlErrorRenderer implements ErrorRendererInterface
2525
{
26+
public const IDE_LINK_FORMATS = [
27+
'textmate' => 'txmt://open?url=file://%f&line=%l',
28+
'macvim' => 'mvim://open?url=file://%f&line=%l',
29+
'emacs' => 'emacs://open?url=file://%f&line=%l',
30+
'sublime' => 'subl://open?url=file://%f&line=%l',
31+
'phpstorm' => 'phpstorm://open?file=%f&line=%l',
32+
'atom' => 'atom://core/open/file?filename=%f&line=%l',
33+
'vscode' => 'vscode://file/%f:%l',
34+
];
35+
2636
private const GHOST_ADDONS = [
2737
'02-14' => self::GHOST_HEART,
2838
'02-29' => self::GHOST_PLUS,
@@ -50,7 +60,10 @@ public function __construct(bool|callable $debug = false, string $charset = null
5060
{
5161
$this->debug = \is_bool($debug) ? $debug : $debug(...);
5262
$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'));
63+
$fileLinkFormat ??= $_SERVER['SYMFONY_IDE'] ?? null;
64+
$this->fileLinkFormat = is_string($fileLinkFormat)
65+
? (self::LINK_FORMATS[$fileLinkFormat] ?? $fileLinkFormat ?: false)
66+
: ($fileLinkFormat ?: ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format') ?: false);
5467
$this->projectDir = $projectDir;
5568
$this->outputBuffer = \is_string($outputBuffer) ? $outputBuffer : $outputBuffer(...);
5669
$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\HtmlErrorRenderer;
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 = (HtmlErrorRenderer::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)