Submit
Path:
~
/
/
usr
/
local
/
psa
/
admin
/
plib
/
modules
/
performance-booster
/
vendor
/
symfony
/
serializer
/
Normalizer
/
File Content:
ProblemNormalizer.php
<?php /* * This file is part of the Symfony package. * * (c) Fabien Potencier <fabien@symfony.com> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PerformanceBooster\Symfony\Component\Serializer\Normalizer; use PerformanceBooster\Symfony\Component\ErrorHandler\Exception\FlattenException; use PerformanceBooster\Symfony\Component\HttpKernel\Exception\HttpExceptionInterface; use PerformanceBooster\Symfony\Component\Messenger\Exception\ValidationFailedException as MessageValidationFailedException; use PerformanceBooster\Symfony\Component\Serializer\Exception\InvalidArgumentException; use PerformanceBooster\Symfony\Component\Serializer\Exception\PartialDenormalizationException; use PerformanceBooster\Symfony\Component\Serializer\SerializerAwareInterface; use PerformanceBooster\Symfony\Component\Serializer\SerializerAwareTrait; use PerformanceBooster\Symfony\Component\Validator\Exception\ValidationFailedException; use PerformanceBooster\Symfony\Contracts\Translation\TranslatorInterface; /** * Normalizes errors according to the API Problem spec (RFC 7807). * * @see https://tools.ietf.org/html/rfc7807 * * @author Kévin Dunglas <dunglas@gmail.com> * @author Yonel Ceruto <yonelceruto@gmail.com> */ class ProblemNormalizer implements NormalizerInterface, SerializerAwareInterface, CacheableSupportsMethodInterface { use SerializerAwareTrait; public const TITLE = 'title'; public const TYPE = 'type'; public const STATUS = 'status'; public function __construct(private bool $debug = \false, private array $defaultContext = [], private ?TranslatorInterface $translator = null) { } public function getSupportedTypes(?string $format) : array { return [FlattenException::class => __CLASS__ === self::class || $this->hasCacheableSupportsMethod()]; } public function normalize(mixed $object, ?string $format = null, array $context = []) : array { if (!$object instanceof FlattenException) { throw new InvalidArgumentException(\sprintf('The object must implement "%s".', FlattenException::class)); } $data = []; $context += $this->defaultContext; $debug = $this->debug && ($context['debug'] ?? \true); $exception = $context['exception'] ?? null; if ($exception instanceof HttpExceptionInterface) { $exception = $exception->getPrevious(); if ($exception instanceof PartialDenormalizationException) { $trans = $this->translator ? $this->translator->trans(...) : fn($m, $p) => \strtr($m, $p); $template = 'This value should be of type {{ type }}.'; $data = [self::TYPE => 'https://symfony.com/errors/validation', self::TITLE => 'Validation Failed', 'violations' => \array_map(fn($e) => ['propertyPath' => $e->getPath(), 'title' => $trans($template, ['{{ type }}' => \implode('|', $e->getExpectedTypes() ?? ['?'])], 'validators'), 'template' => $template, 'parameters' => ['{{ type }}' => \implode('|', $e->getExpectedTypes() ?? ['?'])]] + ($debug || $e->canUseMessageForUser() ? ['hint' => $e->getMessage()] : []), $exception->getErrors())]; $data['detail'] = \implode("\n", \array_map(fn($e) => $e['propertyPath'] . ': ' . $e['title'], $data['violations'])); } elseif (($exception instanceof ValidationFailedException || $exception instanceof MessageValidationFailedException) && $this->serializer instanceof NormalizerInterface && $this->serializer->supportsNormalization($exception->getViolations(), $format, $context)) { $data = $this->serializer->normalize($exception->getViolations(), $format, $context); } } $data = [self::TYPE => $data[self::TYPE] ?? $context[self::TYPE] ?? 'https://tools.ietf.org/html/rfc2616#section-10', self::TITLE => $data[self::TITLE] ?? $context[self::TITLE] ?? 'An error occurred', self::STATUS => $context[self::STATUS] ?? $object->getStatusCode(), 'detail' => $data['detail'] ?? ($debug ? $object->getMessage() : $object->getStatusText())] + $data; if ($debug) { $data['class'] = $object->getClass(); $data['trace'] = $object->getTrace(); } return $data; } /** * @param array $context */ public function supportsNormalization(mixed $data, ?string $format = null) : bool { return $data instanceof FlattenException; } /** * @deprecated since Symfony 6.3, use "getSupportedTypes()" instead */ public function hasCacheableSupportsMethod() : bool { trigger_deprecation('symfony/serializer', '6.3', 'The "%s()" method is deprecated, implement "%s::getSupportedTypes()" instead.', __METHOD__, \get_debug_type($this)); return \true; } }
Submit
FILE
FOLDER
INFO
Name
Size
Permission
Action
AbstractNormalizer.php
25063 bytes
0644
AbstractObjectNormalizer.php
38443 bytes
0644
ArrayDenormalizer.php
4381 bytes
0644
BackedEnumNormalizer.php
3643 bytes
0644
CacheableSupportsMethodInterface.php
806 bytes
0644
ConstraintViolationListNormalizer.php
4604 bytes
0644
ContextAwareDenormalizerInterface.php
827 bytes
0644
ContextAwareNormalizerInterface.php
801 bytes
0644
CustomNormalizer.php
2893 bytes
0644
DataUriNormalizer.php
5874 bytes
0644
DateIntervalNormalizer.php
5025 bytes
0644
DateTimeNormalizer.php
6617 bytes
0644
DateTimeZoneNormalizer.php
2974 bytes
0644
DenormalizableInterface.php
1658 bytes
0644
DenormalizerAwareInterface.php
563 bytes
0644
DenormalizerAwareTrait.php
639 bytes
0644
DenormalizerInterface.php
3575 bytes
0644
FormErrorNormalizer.php
2517 bytes
0644
GetSetMethodNormalizer.php
8172 bytes
0644
JsonSerializableNormalizer.php
2620 bytes
0644
MimeMessageNormalizer.php
5231 bytes
0644
NormalizableInterface.php
1475 bytes
0644
NormalizerAwareInterface.php
553 bytes
0644
NormalizerAwareTrait.php
623 bytes
0644
NormalizerInterface.php
2993 bytes
0644
ObjectNormalizer.php
10093 bytes
0644
ObjectToPopulateTrait.php
1073 bytes
0644
ProblemNormalizer.php
4867 bytes
0644
PropertyNormalizer.php
8364 bytes
0644
TranslatableNormalizer.php
1962 bytes
0644
UidNormalizer.php
4541 bytes
0644
UnwrappingDenormalizer.php
2708 bytes
0644
N4ST4R_ID | Naxtarrr