|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Ivory Http Adapter package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Eric GELOEN <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please read the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Ivory\HttpAdapter\Event; |
|
13
|
|
|
|
|
14
|
|
|
use Ivory\HttpAdapter\HttpAdapterException; |
|
15
|
|
|
use Ivory\HttpAdapter\HttpAdapterInterface; |
|
16
|
|
|
use Ivory\HttpAdapter\Message\InternalRequestInterface; |
|
17
|
|
|
use Ivory\HttpAdapter\Message\ResponseInterface; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @author GeLo <[email protected]> |
|
21
|
|
|
*/ |
|
22
|
|
|
class MultiRequestCreatedEvent extends AbstractEvent |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* @var InternalRequestInterface[] |
|
26
|
|
|
*/ |
|
27
|
|
|
private $requests; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @var ResponseInterface[] |
|
31
|
|
|
*/ |
|
32
|
|
|
private $responses = []; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @var HttpAdapterException[] |
|
36
|
|
|
*/ |
|
37
|
|
|
private $exceptions = []; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @param HttpAdapterInterface $httpAdapter |
|
41
|
|
|
* @param array $requests |
|
42
|
|
|
*/ |
|
43
|
306 |
|
public function __construct(HttpAdapterInterface $httpAdapter, array $requests) |
|
44
|
|
|
{ |
|
45
|
306 |
|
parent::__construct($httpAdapter); |
|
46
|
|
|
|
|
47
|
306 |
|
$this->setRequests($requests); |
|
48
|
306 |
|
} |
|
49
|
|
|
|
|
50
|
306 |
|
public function clearRequests() |
|
51
|
|
|
{ |
|
52
|
306 |
|
$this->requests = []; |
|
53
|
306 |
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @return bool |
|
57
|
|
|
*/ |
|
58
|
54 |
|
public function hasRequests() |
|
59
|
|
|
{ |
|
60
|
54 |
|
return !empty($this->requests); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @return InternalRequestInterface[] |
|
65
|
|
|
*/ |
|
66
|
180 |
|
public function getRequests() |
|
67
|
|
|
{ |
|
68
|
180 |
|
return $this->requests; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @param InternalRequestInterface[] $requests |
|
73
|
|
|
*/ |
|
74
|
306 |
|
public function setRequests(array $requests) |
|
75
|
|
|
{ |
|
76
|
306 |
|
$this->clearRequests(); |
|
77
|
306 |
|
$this->addRequests($requests); |
|
78
|
306 |
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* @param InternalRequestInterface[] $requests |
|
82
|
|
|
*/ |
|
83
|
306 |
|
public function addRequests(array $requests) |
|
84
|
|
|
{ |
|
85
|
306 |
|
foreach ($requests as $request) { |
|
86
|
306 |
|
$this->addRequest($request); |
|
87
|
238 |
|
} |
|
88
|
306 |
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* @param InternalRequestInterface[] $requests |
|
92
|
|
|
*/ |
|
93
|
9 |
|
public function removeRequests(array $requests) |
|
94
|
|
|
{ |
|
95
|
9 |
|
foreach ($requests as $request) { |
|
96
|
9 |
|
$this->removeRequest($request); |
|
97
|
7 |
|
} |
|
98
|
9 |
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* @param InternalRequestInterface $request |
|
102
|
|
|
* |
|
103
|
|
|
* @return bool |
|
104
|
|
|
*/ |
|
105
|
45 |
|
public function hasRequest(InternalRequestInterface $request) |
|
106
|
|
|
{ |
|
107
|
45 |
|
return array_search($request, $this->requests, true) !== false; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* @param InternalRequestInterface $request |
|
112
|
|
|
*/ |
|
113
|
306 |
|
public function addRequest(InternalRequestInterface $request) |
|
114
|
|
|
{ |
|
115
|
306 |
|
$this->requests[] = $request; |
|
116
|
306 |
|
} |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* @param InternalRequestInterface $request |
|
120
|
|
|
*/ |
|
121
|
81 |
|
public function removeRequest(InternalRequestInterface $request) |
|
122
|
|
|
{ |
|
123
|
81 |
|
unset($this->requests[array_search($request, $this->requests, true)]); |
|
124
|
81 |
|
$this->requests = array_values($this->requests); |
|
125
|
81 |
|
} |
|
126
|
|
|
|
|
127
|
36 |
|
public function clearResponses() |
|
128
|
|
|
{ |
|
129
|
36 |
|
$this->responses = []; |
|
130
|
36 |
|
} |
|
131
|
|
|
|
|
132
|
|
|
/** |
|
133
|
|
|
* @return bool |
|
134
|
|
|
*/ |
|
135
|
45 |
|
public function hasResponses() |
|
136
|
|
|
{ |
|
137
|
45 |
|
return !empty($this->responses); |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
/** |
|
141
|
|
|
* @return ResponseInterface[] |
|
142
|
|
|
*/ |
|
143
|
117 |
|
public function getResponses() |
|
144
|
|
|
{ |
|
145
|
117 |
|
return $this->responses; |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
/** |
|
149
|
|
|
* @param ResponseInterface[] $responses |
|
150
|
|
|
*/ |
|
151
|
36 |
|
public function setResponses(array $responses) |
|
152
|
|
|
{ |
|
153
|
36 |
|
$this->clearResponses(); |
|
154
|
36 |
|
$this->addResponses($responses); |
|
155
|
36 |
|
} |
|
156
|
|
|
|
|
157
|
|
|
/** |
|
158
|
|
|
* @param ResponseInterface[] $responses |
|
159
|
|
|
*/ |
|
160
|
36 |
|
public function addResponses(array $responses) |
|
161
|
|
|
{ |
|
162
|
36 |
|
foreach ($responses as $response) { |
|
163
|
36 |
|
$this->addResponse($response); |
|
164
|
28 |
|
} |
|
165
|
36 |
|
} |
|
166
|
|
|
|
|
167
|
|
|
/** |
|
168
|
|
|
* @param ResponseInterface[] $responses |
|
169
|
|
|
*/ |
|
170
|
9 |
|
public function removeResponses(array $responses) |
|
171
|
|
|
{ |
|
172
|
9 |
|
foreach ($responses as $response) { |
|
173
|
9 |
|
$this->removeResponse($response); |
|
174
|
7 |
|
} |
|
175
|
9 |
|
} |
|
176
|
|
|
|
|
177
|
|
|
/** |
|
178
|
|
|
* @param ResponseInterface $response |
|
179
|
|
|
* |
|
180
|
|
|
* @return bool |
|
181
|
|
|
*/ |
|
182
|
36 |
|
public function hasResponse(ResponseInterface $response) |
|
183
|
|
|
{ |
|
184
|
36 |
|
return array_search($response, $this->responses, true) !== false; |
|
185
|
|
|
} |
|
186
|
|
|
|
|
187
|
|
|
/** |
|
188
|
|
|
* @param ResponseInterface $response |
|
189
|
|
|
*/ |
|
190
|
63 |
|
public function addResponse(ResponseInterface $response) |
|
191
|
|
|
{ |
|
192
|
63 |
|
$this->responses[] = $response; |
|
193
|
63 |
|
} |
|
194
|
|
|
|
|
195
|
|
|
/** |
|
196
|
|
|
* @param ResponseInterface $response |
|
197
|
|
|
*/ |
|
198
|
18 |
|
public function removeResponse(ResponseInterface $response) |
|
199
|
|
|
{ |
|
200
|
18 |
|
unset($this->responses[array_search($response, $this->responses, true)]); |
|
201
|
18 |
|
$this->responses = array_values($this->responses); |
|
202
|
18 |
|
} |
|
203
|
|
|
|
|
204
|
36 |
|
public function clearExceptions() |
|
205
|
|
|
{ |
|
206
|
36 |
|
$this->exceptions = []; |
|
207
|
36 |
|
} |
|
208
|
|
|
|
|
209
|
|
|
/** |
|
210
|
|
|
* @return bool |
|
211
|
|
|
*/ |
|
212
|
45 |
|
public function hasExceptions() |
|
213
|
|
|
{ |
|
214
|
45 |
|
return !empty($this->exceptions); |
|
215
|
|
|
} |
|
216
|
|
|
|
|
217
|
|
|
/** |
|
218
|
|
|
* @return HttpAdapterException[] |
|
219
|
|
|
*/ |
|
220
|
117 |
|
public function getExceptions() |
|
221
|
|
|
{ |
|
222
|
117 |
|
return $this->exceptions; |
|
223
|
|
|
} |
|
224
|
|
|
|
|
225
|
|
|
/** |
|
226
|
|
|
* @param HttpAdapterException[] $exceptions |
|
227
|
|
|
*/ |
|
228
|
36 |
|
public function setExceptions(array $exceptions) |
|
229
|
|
|
{ |
|
230
|
36 |
|
$this->clearExceptions(); |
|
231
|
36 |
|
$this->addExceptions($exceptions); |
|
232
|
36 |
|
} |
|
233
|
|
|
|
|
234
|
|
|
/** |
|
235
|
|
|
* @param HttpAdapterException[] $exceptions |
|
236
|
|
|
*/ |
|
237
|
36 |
|
public function addExceptions(array $exceptions) |
|
238
|
|
|
{ |
|
239
|
36 |
|
foreach ($exceptions as $exception) { |
|
240
|
36 |
|
$this->addException($exception); |
|
241
|
28 |
|
} |
|
242
|
36 |
|
} |
|
243
|
|
|
|
|
244
|
|
|
/** |
|
245
|
|
|
* @param HttpAdapterException[] $exceptions |
|
246
|
|
|
*/ |
|
247
|
9 |
|
public function removeExceptions(array $exceptions) |
|
248
|
|
|
{ |
|
249
|
9 |
|
foreach ($exceptions as $exception) { |
|
250
|
9 |
|
$this->removeException($exception); |
|
251
|
7 |
|
} |
|
252
|
9 |
|
} |
|
253
|
|
|
|
|
254
|
|
|
/** |
|
255
|
|
|
* @param HttpAdapterException $exception |
|
256
|
|
|
* |
|
257
|
|
|
* @return bool |
|
258
|
|
|
*/ |
|
259
|
36 |
|
public function hasException(HttpAdapterException $exception) |
|
260
|
|
|
{ |
|
261
|
36 |
|
return array_search($exception, $this->exceptions, true) !== false; |
|
262
|
|
|
} |
|
263
|
|
|
|
|
264
|
|
|
/** |
|
265
|
|
|
* @param HttpAdapterException $exception |
|
266
|
|
|
*/ |
|
267
|
63 |
|
public function addException(HttpAdapterException $exception) |
|
268
|
|
|
{ |
|
269
|
63 |
|
$this->exceptions[] = $exception; |
|
270
|
63 |
|
} |
|
271
|
|
|
|
|
272
|
|
|
/** |
|
273
|
|
|
* @param HttpAdapterException $exception |
|
274
|
|
|
*/ |
|
275
|
18 |
|
public function removeException(HttpAdapterException $exception) |
|
276
|
|
|
{ |
|
277
|
18 |
|
unset($this->exceptions[array_search($exception, $this->exceptions, true)]); |
|
278
|
18 |
|
$this->exceptions = array_values($this->exceptions); |
|
279
|
18 |
|
} |
|
280
|
|
|
} |
|
281
|
|
|
|