Rename normalize param

This commit is contained in:
Vincent Langlet 2021-01-06 12:56:58 +01:00
parent 9b719ab13d
commit 7e6eee2789
1 changed files with 10 additions and 5 deletions

View File

@ -12,6 +12,7 @@
namespace Symfony\Component\Serializer\Normalizer;
use Symfony\Component\ErrorHandler\Exception\FlattenException;
use Symfony\Component\Serializer\Exception\InvalidArgumentException;
/**
* Normalizes errors according to the API Problem spec (RFC 7807).
@ -40,20 +41,24 @@ class ProblemNormalizer implements NormalizerInterface, CacheableSupportsMethodI
*
* @return array
*/
public function normalize($exception, $format = null, array $context = [])
public function normalize($object, $format = null, array $context = [])
{
if (!$object instanceof FlattenException) {
throw new InvalidArgumentException(sprintf('The object must implement "%s".', FlattenException::class));
}
$context += $this->defaultContext;
$debug = $this->debug && ($context['debug'] ?? true);
$data = [
'type' => $context['type'],
'title' => $context['title'],
'status' => $context['status'] ?? $exception->getStatusCode(),
'detail' => $debug ? $exception->getMessage() : $exception->getStatusText(),
'status' => $context['status'] ?? $object->getStatusCode(),
'detail' => $debug ? $object->getMessage() : $object->getStatusText(),
];
if ($debug) {
$data['class'] = $exception->getClass();
$data['trace'] = $exception->getTrace();
$data['class'] = $object->getClass();
$data['trace'] = $object->getTrace();
}
return $data;