Aggiornato Composer
This commit is contained in:
@@ -47,7 +47,7 @@ class HtmlErrorRenderer implements ErrorRendererInterface
|
||||
* @param string|FileLinkFormatter|null $fileLinkFormat
|
||||
* @param bool|callable $outputBuffer The output buffer as a string or a callable that should return it
|
||||
*/
|
||||
public function __construct($debug = false, string $charset = null, $fileLinkFormat = null, string $projectDir = null, $outputBuffer = '', LoggerInterface $logger = null)
|
||||
public function __construct($debug = false, ?string $charset = null, $fileLinkFormat = null, ?string $projectDir = null, $outputBuffer = '', ?LoggerInterface $logger = null)
|
||||
{
|
||||
if (!\is_bool($debug) && !\is_callable($debug)) {
|
||||
throw new \TypeError(sprintf('Argument 1 passed to "%s()" must be a boolean or a callable, "%s" given.', __METHOD__, \gettype($debug)));
|
||||
@@ -58,8 +58,8 @@ class HtmlErrorRenderer implements ErrorRendererInterface
|
||||
}
|
||||
|
||||
$this->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'));
|
||||
$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'));
|
||||
$this->projectDir = $projectDir;
|
||||
$this->outputBuffer = $outputBuffer;
|
||||
$this->logger = $logger;
|
||||
@@ -173,6 +173,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)));
|
||||
}
|
||||
@@ -233,7 +235,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);
|
||||
|
||||
@@ -269,13 +271,25 @@ class HtmlErrorRenderer implements ErrorRendererInterface
|
||||
// highlight_file could throw warnings
|
||||
// see https://bugs.php.net/25725
|
||||
$code = @highlight_file($file, true);
|
||||
// remove main code/span tags
|
||||
$code = preg_replace('#^<code.*?>\s*<span.*?>(.*)</span>\s*</code>#s', '\\1', $code);
|
||||
// split multiline spans
|
||||
$code = preg_replace_callback('#<span ([^>]++)>((?:[^<]*+<br \/>)++[^<]*+)</span>#', function ($m) {
|
||||
return "<span $m[1]>".str_replace('<br />', "</span><br /><span $m[1]>", $m[2]).'</span>';
|
||||
}, $code);
|
||||
$content = explode('<br />', $code);
|
||||
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>#', function ($m) {
|
||||
return "<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);
|
||||
$content = explode("\n", $code);
|
||||
} else {
|
||||
// remove main code/span tags
|
||||
$code = preg_replace('#^<code.*?>\s*<span.*?>(.*)</span>\s*</code>#s', '\\1', $code);
|
||||
// split multiline spans
|
||||
$code = preg_replace_callback('#<span ([^>]++)>((?:[^<]*+<br \/>)++[^<]*+)</span>#', function ($m) {
|
||||
return "<span $m[1]>".str_replace('<br />', "</span><br /><span $m[1]>", $m[2]).'</span>';
|
||||
}, $code);
|
||||
$content = explode('<br />', $code);
|
||||
}
|
||||
|
||||
$lines = [];
|
||||
if (0 > $srcContext) {
|
||||
@@ -315,7 +329,7 @@ class HtmlErrorRenderer implements ErrorRendererInterface
|
||||
{
|
||||
return preg_replace_callback('/in ("|")?(.+?)\1(?: +(?:on|at))? +line (\d+)/s', function ($match) {
|
||||
return 'in '.$this->formatFile($match[2], $match[3]);
|
||||
}, $text);
|
||||
}, $text) ?? $text;
|
||||
}
|
||||
|
||||
private function formatLogMessage(string $message, array $context)
|
||||
@@ -323,7 +337,7 @@ class HtmlErrorRenderer implements ErrorRendererInterface
|
||||
if ($context && false !== strpos($message, '{')) {
|
||||
$replacements = [];
|
||||
foreach ($context as $key => $val) {
|
||||
if (is_scalar($val)) {
|
||||
if (\is_scalar($val)) {
|
||||
$replacements['{'.$key.'}'] = $val;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user