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

Breadcrumb

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

function RequestPayloadValueResolver::resolve

Overrides ValueResolverInterface::resolve

File

vendor/symfony/http-kernel/Controller/ArgumentResolver/RequestPayloadValueResolver.php, line 72

Class

RequestPayloadValueResolver
@author Konstantin Myakshin <molodchick@gmail.com>

Namespace

Symfony\Component\HttpKernel\Controller\ArgumentResolver

Code

public function resolve(Request $request, ArgumentMetadata $argument) : iterable {
    $attribute = $argument->getAttributesOfType(MapQueryString::class, ArgumentMetadata::IS_INSTANCEOF)[0] ?? $argument->getAttributesOfType(MapRequestPayload::class, ArgumentMetadata::IS_INSTANCEOF)[0] ?? $argument->getAttributesOfType(MapUploadedFile::class, ArgumentMetadata::IS_INSTANCEOF)[0] ?? null;
    if (!$attribute) {
        return [];
    }
    if (!$attribute instanceof MapUploadedFile && $argument->isVariadic()) {
        throw new \LogicException(\sprintf('Mapping variadic argument "$%s" is not supported.', $argument->getName()));
    }
    if ($attribute instanceof MapRequestPayload) {
        if ('array' === $argument->getType()) {
            if (!$attribute->type) {
                throw new NearMissValueResolverException(\sprintf('Please set the $type argument of the #[%s] attribute to the type of the objects in the expected array.', MapRequestPayload::class));
            }
        }
        elseif ($attribute->type) {
            throw new NearMissValueResolverException(\sprintf('Please set its type to "array" when using argument $type of #[%s].', MapRequestPayload::class));
        }
    }
    $attribute->metadata = $argument;
    return [
        $attribute,
    ];
}

API Navigation

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