serializer = $serializer; $this->requestSchema = $requestSchema; } /** * {@inheritdoc } */ public function supports(Request $request, ArgumentMetadata $argument): bool { if (empty($this->requestSchema) || $request->getMethod() !== Request::METHOD_POST) { return false; } return null !== $this->search($request, $argument); } /** * {@inheritdoc } */ public function resolve(Request $request, ArgumentMetadata $argument): Generator { $parameter = $this->search($request, $argument); $data = $this->serializer->deserialize($request->request->get($parameter), $argument->getType(), 'json'); $this->validate($data); yield $data; } /** * @param Request $request * @param ArgumentMetadata $argument * * @return string|null */ private function search(Request $request, ArgumentMetadata $argument): ?string { foreach ($this->requestSchema as $callback) { if ($argument->getType() !== $callback['type']) { continue; } foreach ($callback['params'] as $param) { if ($request->request->has($param)) { return $param; } } } return null; } }