1 | <?php |
||
23 | class Client implements HttpClient, HttpAsyncClient |
||
24 | { |
||
25 | use HttpAsyncClientEmulator; |
||
26 | |||
27 | /** |
||
28 | * @var ResponseFactory |
||
29 | */ |
||
30 | private $responseFactory; |
||
31 | |||
32 | /** |
||
33 | * @var RequestInterface[] |
||
34 | */ |
||
35 | private $requests = []; |
||
36 | |||
37 | /** |
||
38 | * @var ResponseInterface[] |
||
39 | */ |
||
40 | private $responses = []; |
||
41 | |||
42 | /** |
||
43 | * @var Exception[] |
||
44 | */ |
||
45 | private $exceptions = []; |
||
46 | |||
47 | /** |
||
48 | * @param ResponseFactory|null $responseFactory |
||
49 | */ |
||
50 | 9 | public function __construct(ResponseFactory $responseFactory = null) |
|
51 | { |
||
52 | 9 | $this->responseFactory = $responseFactory ?: MessageFactoryDiscovery::find(); |
|
53 | 9 | } |
|
54 | |||
55 | /** |
||
56 | * {@inheritdoc} |
||
57 | */ |
||
58 | 4 | public function sendRequest(RequestInterface $request) |
|
73 | |||
74 | /** |
||
75 | * Adds an exception that will be thrown. |
||
76 | * |
||
77 | * @param \Exception $exception |
||
78 | */ |
||
79 | 2 | public function addException(\Exception $exception) |
|
83 | |||
84 | /** |
||
85 | * Adds a response that will be returned. |
||
86 | * |
||
87 | * @param ResponseInterface $response |
||
88 | */ |
||
89 | 2 | public function addResponse(ResponseInterface $response) |
|
93 | |||
94 | /** |
||
95 | * Returns requests that were sent. |
||
96 | * |
||
97 | * @return RequestInterface[] |
||
98 | */ |
||
99 | public function getRequests() |
||
103 | |||
104 | /** |
||
105 | * @return RequestInterface|false |
||
106 | */ |
||
107 | 1 | public function getLastRequest() |
|
111 | |||
112 | /** |
||
113 | * @return Exception|false |
||
114 | */ |
||
115 | 1 | public function getLastException() |
|
119 | |||
120 | /** |
||
121 | * @return ResponseInterface|false |
||
122 | */ |
||
123 | 1 | public function getLastResponse() |
|
127 | } |
||
128 |