Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. RequestPayloadValueResolver.php

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\ArgumentResolver

Code

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);
    }
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal