Update dependencies

This commit is contained in:
Chris Hunt
2024-02-16 21:36:54 +00:00
parent 22d7a59e59
commit d52ae0d3c3
9569 changed files with 460443 additions and 282416 deletions

View File

@@ -24,38 +24,27 @@ use Symfony\Component\Serializer\SerializerInterface;
*/
class SerializerErrorRenderer implements ErrorRendererInterface
{
private $serializer;
private $format;
private $fallbackErrorRenderer;
private $debug;
private SerializerInterface $serializer;
private string|\Closure $format;
private ErrorRendererInterface $fallbackErrorRenderer;
private bool|\Closure $debug;
/**
* @param string|callable(FlattenException) $format The format as a string or a callable that should return it
* 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, $format, ErrorRendererInterface $fallbackErrorRenderer = null, $debug = false)
public function __construct(SerializerInterface $serializer, string|callable $format, ?ErrorRendererInterface $fallbackErrorRenderer = null, bool|callable $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__, \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__, \gettype($debug)));
}
$this->serializer = $serializer;
$this->format = $format;
$this->format = \is_string($format) ? $format : $format(...);
$this->fallbackErrorRenderer = $fallbackErrorRenderer ?? new HtmlErrorRenderer();
$this->debug = $debug;
$this->debug = \is_bool($debug) ? $debug : $debug(...);
}
/**
* {@inheritdoc}
*/
public function render(\Throwable $exception): FlattenException
{
$headers = [];
$headers = ['Vary' => 'Accept'];
$debug = \is_bool($this->debug) ? $this->debug : ($this->debug)($exception);
if ($debug) {
$headers['X-Debug-Exception'] = rawurlencode($exception->getMessage());
@@ -66,19 +55,17 @@ class SerializerErrorRenderer implements ErrorRendererInterface
try {
$format = \is_string($this->format) ? $this->format : ($this->format)($flattenException);
$headers = [
'Content-Type' => Request::getMimeTypes($format)[0] ?? $format,
'Vary' => 'Accept',
];
$headers['Content-Type'] = Request::getMimeTypes($format)[0] ?? $format;
return $flattenException->setAsString($this->serializer->serialize($flattenException, $format, [
$flattenException->setAsString($this->serializer->serialize($flattenException, $format, [
'exception' => $exception,
'debug' => $debug,
]))
->setHeaders($flattenException->getHeaders() + $headers);
} catch (NotEncodableValueException $e) {
return $this->fallbackErrorRenderer->render($exception);
]));
} catch (NotEncodableValueException) {
$flattenException = $this->fallbackErrorRenderer->render($exception);
}
return $flattenException->setHeaders($flattenException->getHeaders() + $headers);
}
public static function getPreferredFormat(RequestStack $requestStack): \Closure