upgraded dependencies
This commit is contained in:
@@ -40,6 +40,8 @@ class HtmlErrorRenderer implements ErrorRendererInterface
|
||||
private $outputBuffer;
|
||||
private $logger;
|
||||
|
||||
private static $template = 'views/error.html.php';
|
||||
|
||||
/**
|
||||
* @param bool|callable $debug The debugging mode as a boolean or a callable that should return it
|
||||
* @param string|FileLinkFormatter|null $fileLinkFormat
|
||||
@@ -48,11 +50,11 @@ class HtmlErrorRenderer implements ErrorRendererInterface
|
||||
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__, \is_object($debug) ? \get_class($debug) : \gettype($debug)));
|
||||
throw new \TypeError(sprintf('Argument 1 passed to "%s()" must be a boolean or a callable, "%s" given.', __METHOD__, \gettype($debug)));
|
||||
}
|
||||
|
||||
if (!\is_string($outputBuffer) && !\is_callable($outputBuffer)) {
|
||||
throw new \TypeError(sprintf('Argument 5 passed to "%s()" must be a string or a callable, "%s" given.', __METHOD__, \is_object($outputBuffer) ? \get_class($outputBuffer) : \gettype($outputBuffer)));
|
||||
throw new \TypeError(sprintf('Argument 5 passed to "%s()" must be a string or a callable, "%s" given.', __METHOD__, \gettype($outputBuffer)));
|
||||
}
|
||||
|
||||
$this->debug = $debug;
|
||||
@@ -68,9 +70,13 @@ class HtmlErrorRenderer implements ErrorRendererInterface
|
||||
*/
|
||||
public function render(\Throwable $exception): FlattenException
|
||||
{
|
||||
$exception = FlattenException::createFromThrowable($exception, null, [
|
||||
'Content-Type' => 'text/html; charset='.$this->charset,
|
||||
]);
|
||||
$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-File'] = rawurlencode($exception->getFile()).':'.$exception->getLine();
|
||||
}
|
||||
|
||||
$exception = FlattenException::createFromThrowable($exception, null, $headers);
|
||||
|
||||
return $exception->setAsString($this->renderException($exception));
|
||||
}
|
||||
@@ -132,7 +138,7 @@ class HtmlErrorRenderer implements ErrorRendererInterface
|
||||
$statusCode = $this->escape($exception->getStatusCode());
|
||||
|
||||
if (!$debug) {
|
||||
return $this->include('views/error.html.php', [
|
||||
return $this->include(self::$template, [
|
||||
'statusText' => $statusText,
|
||||
'statusCode' => $statusCode,
|
||||
]);
|
||||
@@ -209,7 +215,7 @@ class HtmlErrorRenderer implements ErrorRendererInterface
|
||||
/**
|
||||
* Returns the link for a given file/line pair.
|
||||
*
|
||||
* @return string|false A link or false
|
||||
* @return string|false
|
||||
*/
|
||||
private function getFileLink(string $file, int $line)
|
||||
{
|
||||
@@ -256,8 +262,6 @@ class HtmlErrorRenderer implements ErrorRendererInterface
|
||||
* @param string $file A file path
|
||||
* @param int $line The selected line number
|
||||
* @param int $srcContext The number of displayed lines around or -1 for the whole file
|
||||
*
|
||||
* @return string An HTML string
|
||||
*/
|
||||
private function fileExcerpt(string $file, int $line, int $srcContext = 3): string
|
||||
{
|
||||
@@ -279,7 +283,7 @@ class HtmlErrorRenderer implements ErrorRendererInterface
|
||||
}
|
||||
|
||||
for ($i = max($line - $srcContext, 1), $max = min($line + $srcContext, \count($content)); $i <= $max; ++$i) {
|
||||
$lines[] = '<li'.($i == $line ? ' class="selected"' : '').'><a class="anchor" name="line'.$i.'"></a><code>'.$this->fixCodeMarkup($content[$i - 1]).'</code></li>';
|
||||
$lines[] = '<li'.($i == $line ? ' class="selected"' : '').'><code>'.$this->fixCodeMarkup($content[$i - 1]).'</code></li>';
|
||||
}
|
||||
|
||||
return '<ol start="'.max($line - $srcContext, 1).'">'.implode("\n", $lines).'</ol>';
|
||||
@@ -298,9 +302,9 @@ class HtmlErrorRenderer implements ErrorRendererInterface
|
||||
}
|
||||
|
||||
// missing </span> tag at the end of line
|
||||
$opening = strpos($line, '<span');
|
||||
$closing = strpos($line, '</span>');
|
||||
if (false !== $opening && (false === $closing || $closing > $opening)) {
|
||||
$opening = strrpos($line, '<span');
|
||||
$closing = strrpos($line, '</span>');
|
||||
if (false !== $opening && (false === $closing || $closing < $opening)) {
|
||||
$line .= '</span>';
|
||||
}
|
||||
|
||||
@@ -345,8 +349,19 @@ class HtmlErrorRenderer implements ErrorRendererInterface
|
||||
{
|
||||
extract($context, \EXTR_SKIP);
|
||||
ob_start();
|
||||
include __DIR__.'/../Resources/'.$name;
|
||||
|
||||
include is_file(\dirname(__DIR__).'/Resources/'.$name) ? \dirname(__DIR__).'/Resources/'.$name : $name;
|
||||
|
||||
return trim(ob_get_clean());
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows overriding the default non-debug template.
|
||||
*
|
||||
* @param string $template path to the custom template file to render
|
||||
*/
|
||||
public static function setTemplate(string $template): void
|
||||
{
|
||||
self::$template = $template;
|
||||
}
|
||||
}
|
||||
|
@@ -37,11 +37,11 @@ class SerializerErrorRenderer implements ErrorRendererInterface
|
||||
public function __construct(SerializerInterface $serializer, $format, ErrorRendererInterface $fallbackErrorRenderer = null, $debug = false)
|
||||
{
|
||||
if (!\is_string($format) && !\is_callable($format)) {
|
||||
throw new \TypeError(sprintf('Argument 2 passed to "%s()" must be a string or a callable, "%s" given.', __METHOD__, \is_object($format) ? \get_class($format) : \gettype($format)));
|
||||
throw new \TypeError(sprintf('Argument 2 passed to "%s()" must be a string or a callable, "%s" given.', __METHOD__, \gettype($format)));
|
||||
}
|
||||
|
||||
if (!\is_bool($debug) && !\is_callable($debug)) {
|
||||
throw new \TypeError(sprintf('Argument 4 passed to "%s()" must be a boolean or a callable, "%s" given.', __METHOD__, \is_object($debug) ? \get_class($debug) : \gettype($debug)));
|
||||
throw new \TypeError(sprintf('Argument 4 passed to "%s()" must be a boolean or a callable, "%s" given.', __METHOD__, \gettype($debug)));
|
||||
}
|
||||
|
||||
$this->serializer = $serializer;
|
||||
@@ -55,7 +55,14 @@ class SerializerErrorRenderer implements ErrorRendererInterface
|
||||
*/
|
||||
public function render(\Throwable $exception): FlattenException
|
||||
{
|
||||
$flattenException = FlattenException::createFromThrowable($exception);
|
||||
$headers = [];
|
||||
$debug = \is_bool($this->debug) ? $this->debug : ($this->debug)($exception);
|
||||
if ($debug) {
|
||||
$headers['X-Debug-Exception'] = rawurlencode($exception->getMessage());
|
||||
$headers['X-Debug-Exception-File'] = rawurlencode($exception->getFile()).':'.$exception->getLine();
|
||||
}
|
||||
|
||||
$flattenException = FlattenException::createFromThrowable($exception, null, $headers);
|
||||
|
||||
try {
|
||||
$format = \is_string($this->format) ? $this->format : ($this->format)($flattenException);
|
||||
@@ -66,7 +73,7 @@ class SerializerErrorRenderer implements ErrorRendererInterface
|
||||
|
||||
return $flattenException->setAsString($this->serializer->serialize($flattenException, $format, [
|
||||
'exception' => $exception,
|
||||
'debug' => \is_bool($this->debug) ? $this->debug : ($this->debug)($exception),
|
||||
'debug' => $debug,
|
||||
]))
|
||||
->setHeaders($flattenException->getHeaders() + $headers);
|
||||
} catch (NotEncodableValueException $e) {
|
||||
|
Reference in New Issue
Block a user