Rename normalize param
This commit is contained in:
parent
9b719ab13d
commit
7e6eee2789
@ -12,6 +12,7 @@
|
|||||||
namespace Symfony\Component\Serializer\Normalizer;
|
namespace Symfony\Component\Serializer\Normalizer;
|
||||||
|
|
||||||
use Symfony\Component\ErrorHandler\Exception\FlattenException;
|
use Symfony\Component\ErrorHandler\Exception\FlattenException;
|
||||||
|
use Symfony\Component\Serializer\Exception\InvalidArgumentException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Normalizes errors according to the API Problem spec (RFC 7807).
|
* Normalizes errors according to the API Problem spec (RFC 7807).
|
||||||
@ -40,20 +41,24 @@ class ProblemNormalizer implements NormalizerInterface, CacheableSupportsMethodI
|
|||||||
*
|
*
|
||||||
* @return array
|
* @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;
|
$context += $this->defaultContext;
|
||||||
$debug = $this->debug && ($context['debug'] ?? true);
|
$debug = $this->debug && ($context['debug'] ?? true);
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'type' => $context['type'],
|
'type' => $context['type'],
|
||||||
'title' => $context['title'],
|
'title' => $context['title'],
|
||||||
'status' => $context['status'] ?? $exception->getStatusCode(),
|
'status' => $context['status'] ?? $object->getStatusCode(),
|
||||||
'detail' => $debug ? $exception->getMessage() : $exception->getStatusText(),
|
'detail' => $debug ? $object->getMessage() : $object->getStatusText(),
|
||||||
];
|
];
|
||||||
if ($debug) {
|
if ($debug) {
|
||||||
$data['class'] = $exception->getClass();
|
$data['class'] = $object->getClass();
|
||||||
$data['trace'] = $exception->getTrace();
|
$data['trace'] = $object->getTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
|
Reference in New Issue
Block a user