serializer = $serializer; $this->requestSchema = $requestSchema; } /** * {@inheritdoc} */ public function supports(Request $request, ArgumentMetadata $argument): bool { return in_array($argument->getType(), $this->requestSchema, true); } /** * {@inheritdoc} */ public function resolve(Request $request, ArgumentMetadata $argument): Generator { if (Request::METHOD_GET === $request->getMethod()) { $dto = $this->handleGetData($request->query->all(), $argument->getType()); } else { $dto = $this->handlePostData($request->getContent(), $argument->getType()); } $this->validate($dto); yield $dto; } /** * @param array $data * @param string $type * * @return object */ private function handleGetData(array $data, string $type): object { return $this->serializer->arrayToObject($data, $type); } /** * @param string $data * @param string $type * * @return object */ private function handlePostData(string $data, string $type): object { return $this->serializer->deserialize($data, $type); } }