1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace League\OAuth2\Server; |
4
|
|
|
|
5
|
|
|
use Psr\Http\Message\ResponseInterface; |
6
|
|
|
use Psr\Http\Message\ServerRequestInterface; |
7
|
|
|
use Symfony\Bridge\PsrHttpMessage\Factory\DiactorosFactory; |
8
|
|
|
use Symfony\Bridge\PsrHttpMessage\Factory\HttpFoundationFactory; |
9
|
|
|
use Symfony\Component\HttpFoundation\Request as SymfonyRequest; |
10
|
|
|
use Symfony\Component\HttpFoundation\Response as SymfonyResponse; |
11
|
|
|
|
12
|
|
|
class HttpMessageConverter |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* Convert a Symfony HTTP Request to a Psr7 Response |
16
|
|
|
* |
17
|
|
|
* @param SymfonyRequest $request |
18
|
|
|
* |
19
|
|
|
* @return \Psr\Http\Message\ServerRequestInterface |
20
|
|
|
*/ |
21
|
|
|
public static function convertSymfonyRequestToPsr7(SymfonyRequest $request) |
22
|
|
|
{ |
23
|
|
|
$psr7Factory = new DiactorosFactory(); |
24
|
|
|
|
25
|
|
|
return $psr7Factory->createRequest($request); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Convert a Symfony HTTP Response to a Psr7 Response |
30
|
|
|
* |
31
|
|
|
* @param SymfonyResponse $response |
32
|
|
|
* |
33
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
34
|
|
|
*/ |
35
|
|
|
public static function convertSymfonyResponseToPsr7(SymfonyResponse $response) |
36
|
|
|
{ |
37
|
|
|
$psr7Factory = new DiactorosFactory(); |
38
|
|
|
|
39
|
|
|
return $psr7Factory->createResponse($response); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Convert a Symfony HTTP Request to a Psr7 Response |
44
|
|
|
* |
45
|
|
|
* @param \Psr\Http\Message\ServerRequestInterface $request |
46
|
|
|
* |
47
|
|
|
* @return \Symfony\Component\HttpFoundation\Request |
48
|
|
|
*/ |
49
|
|
|
public static function convertPsr7RequestToSymfony(ServerRequestInterface $request) |
50
|
|
|
{ |
51
|
|
|
$httpFoundationFactory = new HttpFoundationFactory(); |
52
|
|
|
|
53
|
|
|
return $httpFoundationFactory->createRequest($request); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Convert a Symfony HTTP Response to a Psr7 Response |
58
|
|
|
* |
59
|
|
|
* @param \Psr\Http\Message\ResponseInterface $response |
60
|
|
|
* |
61
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
62
|
|
|
*/ |
63
|
|
|
public static function convertPsr7ResponseToSymfony(ResponseInterface $response) |
64
|
|
|
{ |
65
|
|
|
$httpFoundationFactory = new HttpFoundationFactory(); |
66
|
|
|
|
67
|
|
|
return $httpFoundationFactory->createResponse($response); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|