|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the Drest package. |
|
4
|
|
|
* |
|
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
6
|
|
|
* file that was distributed with this source code. |
|
7
|
|
|
* |
|
8
|
|
|
* @author Lee Davis |
|
9
|
|
|
* @copyright Copyright (c) Lee Davis <@leedavis81> |
|
10
|
|
|
* @link https://github.com/leedavis81/drest/blob/master/LICENSE |
|
11
|
|
|
* @license http://opensource.org/licenses/MIT The MIT X License (MIT) |
|
12
|
|
|
*/ |
|
13
|
|
|
namespace Drest; |
|
14
|
|
|
|
|
15
|
|
|
use DrestCommon\Request\Request; |
|
16
|
|
|
use DrestCommon\Response\Response; |
|
17
|
|
|
trait HttpManagerTrait |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* Drest request object |
|
21
|
|
|
* @var Request $request |
|
22
|
|
|
*/ |
|
23
|
|
|
protected $request; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Drest response object |
|
27
|
|
|
* @var Response $response |
|
28
|
|
|
*/ |
|
29
|
|
|
protected $response; |
|
30
|
|
|
|
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Set up the HTTP manager |
|
34
|
|
|
* @param $request |
|
35
|
|
|
* @param $response |
|
36
|
|
|
* @param Configuration $config |
|
37
|
|
|
*/ |
|
38
|
31 |
|
public function setUpHttp($request, $response, Configuration $config) |
|
39
|
|
|
{ |
|
40
|
31 |
|
$this->setRequest(Request::create($request, $config->getRegisteredRequestAdapterClasses())); |
|
41
|
31 |
|
$this->setResponse(Response::create($response, $config->getRegisteredResponseAdapterClasses())); |
|
42
|
31 |
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Get the request object |
|
46
|
|
|
* @return Request $request |
|
47
|
|
|
*/ |
|
48
|
30 |
|
public function getRequest() |
|
49
|
|
|
{ |
|
50
|
30 |
|
if (!$this->request instanceof Request) { |
|
51
|
|
|
$this->request = Request::create(); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
30 |
|
return $this->request; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Set the request object |
|
59
|
|
|
* @param Request $request |
|
60
|
|
|
*/ |
|
61
|
31 |
|
public function setRequest(Request $request) |
|
62
|
|
|
{ |
|
63
|
31 |
|
$this->request = $request; |
|
64
|
31 |
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Get the response object |
|
68
|
|
|
* @return Response $response |
|
69
|
|
|
*/ |
|
70
|
28 |
|
public function getResponse() |
|
71
|
|
|
{ |
|
72
|
28 |
|
if (!$this->response instanceof Response) { |
|
73
|
|
|
$this->response = Response::create(); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
28 |
|
return $this->response; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Set the response object |
|
81
|
|
|
* @param Response $response |
|
82
|
|
|
*/ |
|
83
|
31 |
|
public function setResponse(Response $response) |
|
84
|
|
|
{ |
|
85
|
31 |
|
$this->response = $response; |
|
86
|
31 |
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|