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\ArgumentResolverCode
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,
];
}