forked from Payum/PayumBundle
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReplyToSymfonyResponseConverter.php
More file actions
39 lines (32 loc) · 1.11 KB
/
ReplyToSymfonyResponseConverter.php
File metadata and controls
39 lines (32 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
namespace Payum\Bundle\PayumBundle;
use Payum\Bundle\PayumBundle\Reply\HttpResponse as SymfonyHttpResponse;
use Payum\Core\Bridge\Symfony\Reply\HttpResponse as CoreSymfonyHttpResponse;
use Payum\Core\Exception\LogicException;
use Payum\Core\Reply\HttpResponse;
use Payum\Core\Reply\ReplyInterface;
use ReflectionObject;
use Symfony\Component\HttpFoundation\Response;
class ReplyToSymfonyResponseConverter
{
/**
* @return Response
*/
public function convert(ReplyInterface $reply)
{
if ($reply instanceof SymfonyHttpResponse || $reply instanceof CoreSymfonyHttpResponse) {
return $reply->getResponse();
}
if ($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()),
0,
$reply
);
}
}