Skip to content

Commit

Permalink
Read SYMFONY_IDE to render exception in case of fatal error
Browse files Browse the repository at this point in the history
  • Loading branch information
GromNaN committed Mar 17, 2022
1 parent 9a29631 commit c942cfe
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
1 change: 1 addition & 0 deletions src/Symfony/Component/ErrorHandler/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ CHANGELOG
---

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

5.4
---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@
*/
class HtmlErrorRenderer implements ErrorRendererInterface
{
public const IDE_LINK_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 const GHOST_ADDONS = [
'02-14' => self::GHOST_HEART,
'02-29' => self::GHOST_PLUS,
Expand Down Expand Up @@ -50,7 +60,10 @@ public function __construct(bool|callable $debug = false, string $charset = null
{
$this->debug = \is_bool($debug) ? $debug : $debug(...);
$this->charset = $charset ?: (ini_get('default_charset') ?: 'UTF-8');
$this->fileLinkFormat = $fileLinkFormat ?: (ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format'));
$fileLinkFormat ??= $_SERVER['SYMFONY_IDE'] ?? null;
$this->fileLinkFormat = is_string($fileLinkFormat)
? (self::LINK_FORMATS[$fileLinkFormat] ?? $fileLinkFormat ?: false)
: ($fileLinkFormat ?: ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format') ?: false);
$this->projectDir = $projectDir;
$this->outputBuffer = \is_string($outputBuffer) ? $outputBuffer : $outputBuffer(...);
$this->logger = $logger;
Expand Down
14 changes: 3 additions & 11 deletions src/Symfony/Component/HttpKernel/Debug/FileLinkFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Symfony\Component\HttpKernel\Debug;

use Symfony\Component\ErrorHandler\ErrorRenderer\HtmlErrorRenderer;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
Expand All @@ -24,16 +25,6 @@
*/
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 array|false $fileLinkFormat;
private ?RequestStack $requestStack = null;
private ?string $baseDir = null;
Expand All @@ -44,7 +35,8 @@ class FileLinkFormatter
*/
public function __construct(string $fileLinkFormat = null, RequestStack $requestStack = null, string $baseDir = null, string|\Closure $urlFormat = null)
{
$fileLinkFormat = (self::FORMATS[$fileLinkFormat] ?? $fileLinkFormat) ?: ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format') ?: false;
$fileLinkFormat ??= $_SERVER['SYMFONY_IDE'] ?? null;
$fileLinkFormat = (HtmlErrorRenderer::IDE_LINK_FORMATS[$fileLinkFormat] ?? $fileLinkFormat) ?: ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format') ?: false;
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);
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/HttpKernel/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
],
"require": {
"php": ">=8.1",
"symfony/error-handler": "^5.4|^6.0",
"symfony/error-handler": "^6.1",
"symfony/event-dispatcher": "^5.4|^6.0",
"symfony/http-foundation": "^5.4|^6.0",
"symfony/polyfill-ctype": "^1.8",
Expand Down

0 comments on commit c942cfe

Please sign in to comment.