/** * {@inheritDoc} */ public function convert(ReplyInterface $reply) { $headers = $statusCode = $content = null; if ($reply instanceof SymfonyHttpResponse) { $response = $reply->getResponse(); $statusCode = $response->getStatusCode(); $headers = $response->headers->all(); $content = $response->getContent(); } else { if ($reply instanceof HttpPostRedirect) { $statusCode = $reply->getStatusCode(); $headers = $reply->getHeaders(); $content = $this->preparePostRedirectContent($reply); } else { if ($reply instanceof HttpResponse) { $statusCode = $reply->getStatusCode(); $headers = $reply->getHeaders(); $content = $reply->getContent(); } else { $ro = new \ReflectionObject($reply); throw new LogicException(sprintf('Cannot convert reply %s to http response.', $ro->getShortName()), null, $reply); } } } $fixedHeaders = []; foreach ($headers as $name => $value) { $fixedHeaders[str_replace('- ', '-', ucwords(str_replace('-', '- ', $name)))] = $value; } $fixedHeaders['Content-Type'] = 'application/vnd.payum+json'; return new JsonResponse(['status' => $statusCode, 'headers' => $fixedHeaders, 'content' => $content], $statusCode, ['X-Status-Code' => $statusCode]); }
/** * @param ReplyInterface $reply * * @return Response */ public function convert(ReplyInterface $reply) { if ($reply instanceof SymfonyHttpResponse) { return $reply->getResponse(); } elseif ($reply instanceof HttpResponse) { return new Response($reply->getContent()); } elseif ($reply instanceof HttpRedirect) { return new RedirectResponse($reply->getUrl()); } $ro = new \ReflectionObject($reply); throw new LogicException(sprintf('Cannot convert reply %s to http response.', $ro->getShortName()), null, $reply); }
/** * @param ReplyInterface $reply * * @return Response */ public function convert(ReplyInterface $reply) { if ($reply instanceof SymfonyHttpResponse) { return $reply->getResponse(); } elseif ($reply instanceof HttpResponse) { $headers = $reply->getHeaders(); $headers['X-Status-Code'] = $reply->getStatusCode(); return new Response($reply->getContent(), $reply->getStatusCode(), $headers); } $ro = new \ReflectionObject($reply); throw new LogicException(sprintf('Cannot convert reply %s to http response.', $ro->getShortName()), null, $reply); }