🔧
This commit is contained in:
@@ -30,9 +30,9 @@ class FileLinkFormatter
|
||||
private \Closure|string|null $urlFormat;
|
||||
|
||||
/**
|
||||
* @param string|\Closure $urlFormat the URL format, or a closure that returns it on-demand
|
||||
* @param string|\Closure $urlFormat The URL format, or a closure that returns it on-demand
|
||||
*/
|
||||
public function __construct(string|array $fileLinkFormat = null, RequestStack $requestStack = null, string $baseDir = null, string|\Closure $urlFormat = null)
|
||||
public function __construct(string|array|null $fileLinkFormat = null, ?RequestStack $requestStack = null, ?string $baseDir = null, string|\Closure|null $urlFormat = null)
|
||||
{
|
||||
$fileLinkFormat ??= $_ENV['SYMFONY_IDE'] ?? $_SERVER['SYMFONY_IDE'] ?? '';
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ class HtmlErrorRenderer implements ErrorRendererInterface
|
||||
* @param bool|callable $debug The debugging mode as a boolean or a callable that should return it
|
||||
* @param string|callable $outputBuffer The output buffer as a string or a callable that should return it
|
||||
*/
|
||||
public function __construct(bool|callable $debug = false, string $charset = null, string|FileLinkFormatter $fileLinkFormat = null, string $projectDir = null, string|callable $outputBuffer = '', LoggerInterface $logger = null)
|
||||
public function __construct(bool|callable $debug = false, ?string $charset = null, string|FileLinkFormatter|null $fileLinkFormat = null, ?string $projectDir = null, string|callable $outputBuffer = '', ?LoggerInterface $logger = null)
|
||||
{
|
||||
$this->debug = \is_bool($debug) ? $debug : $debug(...);
|
||||
$this->charset = $charset ?: (\ini_get('default_charset') ?: 'UTF-8');
|
||||
@@ -61,7 +61,7 @@ class HtmlErrorRenderer implements ErrorRendererInterface
|
||||
{
|
||||
$headers = ['Content-Type' => 'text/html; charset='.$this->charset];
|
||||
if (\is_bool($this->debug) ? $this->debug : ($this->debug)($exception)) {
|
||||
$headers['X-Debug-Exception'] = rawurlencode($exception->getMessage());
|
||||
$headers['X-Debug-Exception'] = rawurlencode(substr($exception->getMessage(), 0, 2000));
|
||||
$headers['X-Debug-Exception-File'] = rawurlencode($exception->getFile()).':'.$exception->getLine();
|
||||
}
|
||||
|
||||
@@ -140,7 +140,7 @@ class HtmlErrorRenderer implements ErrorRendererInterface
|
||||
'exceptionMessage' => $exceptionMessage,
|
||||
'statusText' => $statusText,
|
||||
'statusCode' => $statusCode,
|
||||
'logger' => DebugLoggerConfigurator::getDebugLogger($this->logger),
|
||||
'logger' => null !== $this->logger && class_exists(DebugLoggerConfigurator::class) ? DebugLoggerConfigurator::getDebugLogger($this->logger) : null,
|
||||
'currentContent' => \is_string($this->outputBuffer) ? $this->outputBuffer : ($this->outputBuffer)(),
|
||||
]);
|
||||
}
|
||||
@@ -167,6 +167,8 @@ class HtmlErrorRenderer implements ErrorRendererInterface
|
||||
$formattedValue = '<em>'.strtolower(var_export($item[1], true)).'</em>';
|
||||
} elseif ('resource' === $item[0]) {
|
||||
$formattedValue = '<em>resource</em>';
|
||||
} elseif (preg_match('/[^\x07-\x0D\x1B\x20-\xFF]/', $item[1])) {
|
||||
$formattedValue = '<em>binary string</em>';
|
||||
} else {
|
||||
$formattedValue = str_replace("\n", '', $this->escape(var_export($item[1], true)));
|
||||
}
|
||||
@@ -213,7 +215,7 @@ class HtmlErrorRenderer implements ErrorRendererInterface
|
||||
* @param int $line The line number
|
||||
* @param string $text Use this text for the link rather than the file path
|
||||
*/
|
||||
private function formatFile(string $file, int $line, string $text = null): string
|
||||
private function formatFile(string $file, int $line, ?string $text = null): string
|
||||
{
|
||||
$file = trim($file);
|
||||
|
||||
@@ -250,10 +252,10 @@ class HtmlErrorRenderer implements ErrorRendererInterface
|
||||
if (\PHP_VERSION_ID >= 80300) {
|
||||
// remove main pre/code tags
|
||||
$code = preg_replace('#^<pre.*?>\s*<code.*?>(.*)</code>\s*</pre>#s', '\\1', $code);
|
||||
// split multiline code tags
|
||||
$code = preg_replace_callback('#<code ([^>]++)>((?:[^<]*+\\n)++[^<]*+)</code>#', fn ($m) => "<code $m[1]>".str_replace("\n", "</code>\n<code $m[1]>", $m[2]).'</code>', $code);
|
||||
// Convert spaces to html entities to preserve indentation when rendered
|
||||
$code = str_replace(' ', ' ', $code);
|
||||
// split multiline span tags
|
||||
$code = preg_replace_callback('#<span ([^>]++)>((?:[^<\\n]*+\\n)++[^<]*+)</span>#', function ($m) {
|
||||
return "<span $m[1]>".str_replace("\n", "</span>\n<span $m[1]>", $m[2]).'</span>';
|
||||
}, $code);
|
||||
$content = explode("\n", $code);
|
||||
} else {
|
||||
// remove main code/span tags
|
||||
@@ -299,7 +301,7 @@ class HtmlErrorRenderer implements ErrorRendererInterface
|
||||
|
||||
private function formatFileFromText(string $text): string
|
||||
{
|
||||
return preg_replace_callback('/in ("|")?(.+?)\1(?: +(?:on|at))? +line (\d+)/s', fn ($match) => 'in '.$this->formatFile($match[2], $match[3]), $text);
|
||||
return preg_replace_callback('/in ("|")?(.+?)\1(?: +(?:on|at))? +line (\d+)/s', fn ($match) => 'in '.$this->formatFile($match[2], $match[3]), $text) ?? $text;
|
||||
}
|
||||
|
||||
private function formatLogMessage(string $message, array $context): string
|
||||
|
||||
@@ -34,7 +34,7 @@ class SerializerErrorRenderer implements ErrorRendererInterface
|
||||
* formats not supported by Request::getMimeTypes() should be given as mime types
|
||||
* @param bool|callable $debug The debugging mode as a boolean or a callable that should return it
|
||||
*/
|
||||
public function __construct(SerializerInterface $serializer, string|callable $format, ErrorRendererInterface $fallbackErrorRenderer = null, bool|callable $debug = false)
|
||||
public function __construct(SerializerInterface $serializer, string|callable $format, ?ErrorRendererInterface $fallbackErrorRenderer = null, bool|callable $debug = false)
|
||||
{
|
||||
$this->serializer = $serializer;
|
||||
$this->format = \is_string($format) ? $format : $format(...);
|
||||
@@ -47,7 +47,7 @@ class SerializerErrorRenderer implements ErrorRendererInterface
|
||||
$headers = ['Vary' => 'Accept'];
|
||||
$debug = \is_bool($this->debug) ? $this->debug : ($this->debug)($exception);
|
||||
if ($debug) {
|
||||
$headers['X-Debug-Exception'] = rawurlencode($exception->getMessage());
|
||||
$headers['X-Debug-Exception'] = rawurlencode(substr($exception->getMessage(), 0, 2000));
|
||||
$headers['X-Debug-Exception-File'] = rawurlencode($exception->getFile()).':'.$exception->getLine();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user