mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-23 10:38:45 +02:00
N°8834 - Add compatibility with PHP 8.4 (#819)
* N°8834 - Add compatibility with PHP 8.4 * Rollback of scssphp/scssphp version upgrade due to compilation error
This commit is contained in:
@@ -26,7 +26,7 @@ class CliErrorRenderer implements ErrorRendererInterface
|
||||
public function render(\Throwable $exception): FlattenException
|
||||
{
|
||||
$cloner = new VarCloner();
|
||||
$dumper = new class() extends CliDumper {
|
||||
$dumper = new class extends CliDumper {
|
||||
protected function supportsColors(): bool
|
||||
{
|
||||
$outputStream = $this->outputStream;
|
||||
|
||||
@@ -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'] ?? '';
|
||||
|
||||
@@ -67,14 +67,11 @@ class FileLinkFormatter
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public function __sleep(): array
|
||||
public function __serialize(): array
|
||||
{
|
||||
$this->fileLinkFormat = $this->getFileLinkFormat();
|
||||
|
||||
return ['fileLinkFormat'];
|
||||
return ['fileLinkFormat' => $this->fileLinkFormat];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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)(),
|
||||
]);
|
||||
}
|
||||
@@ -158,20 +158,22 @@ class HtmlErrorRenderer implements ErrorRendererInterface
|
||||
$result = [];
|
||||
foreach ($args as $key => $item) {
|
||||
if ('object' === $item[0]) {
|
||||
$formattedValue = sprintf('<em>object</em>(%s)', $this->abbrClass($item[1]));
|
||||
$formattedValue = \sprintf('<em>object</em>(%s)', $this->abbrClass($item[1]));
|
||||
} elseif ('array' === $item[0]) {
|
||||
$formattedValue = sprintf('<em>array</em>(%s)', \is_array($item[1]) ? $this->formatArgs($item[1]) : $item[1]);
|
||||
$formattedValue = \sprintf('<em>array</em>(%s)', \is_array($item[1]) ? $this->formatArgs($item[1]) : $item[1]);
|
||||
} elseif ('null' === $item[0]) {
|
||||
$formattedValue = '<em>null</em>';
|
||||
} elseif ('boolean' === $item[0]) {
|
||||
$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)));
|
||||
}
|
||||
|
||||
$result[] = \is_int($key) ? $formattedValue : sprintf("'%s' => %s", $this->escape($key), $formattedValue);
|
||||
$result[] = \is_int($key) ? $formattedValue : \sprintf("'%s' => %s", $this->escape($key), $formattedValue);
|
||||
}
|
||||
|
||||
return implode(', ', $result);
|
||||
@@ -192,7 +194,7 @@ class HtmlErrorRenderer implements ErrorRendererInterface
|
||||
$parts = explode('\\', $class);
|
||||
$short = array_pop($parts);
|
||||
|
||||
return sprintf('<abbr title="%s">%s</abbr>', $class, $short);
|
||||
return \sprintf('<abbr title="%s">%s</abbr>', $class, $short);
|
||||
}
|
||||
|
||||
private function getFileRelative(string $file): ?string
|
||||
@@ -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);
|
||||
|
||||
@@ -221,7 +223,7 @@ class HtmlErrorRenderer implements ErrorRendererInterface
|
||||
$text = $file;
|
||||
if (null !== $rel = $this->getFileRelative($text)) {
|
||||
$rel = explode('/', $rel, 2);
|
||||
$text = sprintf('<abbr title="%s%2$s">%s</abbr>%s', $this->projectDir, $rel[0], '/'.($rel[1] ?? ''));
|
||||
$text = \sprintf('<abbr title="%s%2$s">%s</abbr>%s', $this->projectDir, $rel[0], '/'.($rel[1] ?? ''));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -229,9 +231,13 @@ class HtmlErrorRenderer implements ErrorRendererInterface
|
||||
$text .= ' at line '.$line;
|
||||
}
|
||||
|
||||
if (!file_exists($file)) {
|
||||
return $text;
|
||||
}
|
||||
|
||||
$link = $this->fileLinkFormat->format($file, $line);
|
||||
|
||||
return sprintf('<a href="%s" title="Click to open this file" class="file_link">%s</a>', $this->escape($link), $text);
|
||||
return \sprintf('<a href="%s" title="Click to open this file" class="file_link">%s</a>', $this->escape($link), $text);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -250,10 +256,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 +305,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