function RequestPayloadValueResolver::mapRequestPayload
1 call to RequestPayloadValueResolver::mapRequestPayload()
- RequestPayloadValueResolver::onKernelControllerArguments in vendor/
symfony/ http-kernel/ Controller/ ArgumentResolver/ RequestPayloadValueResolver.php
File
-
vendor/
symfony/ http-kernel/ Controller/ ArgumentResolver/ RequestPayloadValueResolver.php, line 196
Class
- RequestPayloadValueResolver
- @author Konstantin Myakshin <molodchick@gmail.com>
Namespace
Symfony\Component\HttpKernel\Controller\ArgumentResolverCode
private function mapRequestPayload(Request $request, ArgumentMetadata $argument, MapRequestPayload $attribute) : object|array|null {
if (null === ($format = $request->getContentTypeFormat())) {
throw new UnsupportedMediaTypeHttpException('Unsupported format.');
}
if ($attribute->acceptFormat && !\in_array($format, (array) $attribute->acceptFormat, true)) {
throw new UnsupportedMediaTypeHttpException(\sprintf('Unsupported format, expects "%s", but "%s" given.', implode('", "', (array) $attribute->acceptFormat), $format));
}
if ('array' === $argument->getType() && null !== $attribute->type) {
$type = $attribute->type . '[]';
}
else {
$type = $argument->getType();
}
if ($data = $request->request
->all()) {
return $this->serializer
->denormalize($data, $type, null, $attribute->serializationContext + self::CONTEXT_DENORMALIZE + ('form' === $format ? [
'filter_bool' => true,
] : []));
}
if ('' === ($data = $request->getContent()) && ($argument->isNullable() || $argument->hasDefaultValue())) {
return null;
}
if ('form' === $format) {
throw new BadRequestHttpException('Request payload contains invalid "form" data.');
}
try {
return $this->serializer
->deserialize($data, $type, $format, self::CONTEXT_DESERIALIZE + $attribute->serializationContext);
} catch (UnsupportedFormatException $e) {
throw new UnsupportedMediaTypeHttpException(\sprintf('Unsupported format: "%s".', $format), $e);
} catch (NotEncodableValueException $e) {
throw new BadRequestHttpException(\sprintf('Request payload contains invalid "%s" data.', $format), $e);
} catch (UnexpectedPropertyException $e) {
throw new BadRequestHttpException(\sprintf('Request payload contains invalid "%s" property.', $e->property), $e);
}
}