1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Ivory Google Map 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\GoogleMap\Service\DistanceMatrix\Response; |
13
|
|
|
|
14
|
|
|
use Ivory\GoogleMap\Service\DistanceMatrix\Request\DistanceMatrixRequestInterface; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @author GeLo <[email protected]> |
18
|
|
|
*/ |
19
|
|
|
class DistanceMatrixResponse |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @var string|null |
23
|
|
|
*/ |
24
|
|
|
private $status; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var DistanceMatrixRequestInterface|null |
28
|
|
|
*/ |
29
|
|
|
private $request; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var string[] |
33
|
|
|
*/ |
34
|
|
|
private $origins = []; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var string[] |
38
|
|
|
*/ |
39
|
|
|
private $destinations = []; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var DistanceMatrixRow[] |
43
|
|
|
*/ |
44
|
|
|
private $rows = []; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @return bool |
48
|
|
|
*/ |
49
|
12 |
|
public function hasStatus() |
50
|
|
|
{ |
51
|
12 |
|
return null !== $this->status; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @return string|null |
56
|
|
|
*/ |
57
|
12 |
|
public function getStatus() |
58
|
|
|
{ |
59
|
12 |
|
return $this->status; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @param string|null $status |
64
|
|
|
*/ |
65
|
8 |
|
public function setStatus($status) |
66
|
|
|
{ |
67
|
8 |
|
$this->status = $status; |
68
|
8 |
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @return bool |
72
|
|
|
*/ |
73
|
8 |
|
public function hasRequest() |
74
|
|
|
{ |
75
|
8 |
|
return null !== $this->request; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @return DistanceMatrixRequestInterface|null |
80
|
|
|
*/ |
81
|
8 |
|
public function getRequest() |
82
|
|
|
{ |
83
|
8 |
|
return $this->request; |
84
|
|
|
} |
85
|
|
|
|
86
|
4 |
|
public function setRequest(DistanceMatrixRequestInterface $request = null) |
87
|
|
|
{ |
88
|
4 |
|
$this->request = $request; |
89
|
4 |
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @return bool |
93
|
|
|
*/ |
94
|
20 |
|
public function hasOrigins() |
95
|
|
|
{ |
96
|
20 |
|
return !empty($this->origins); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @return string[] |
101
|
|
|
*/ |
102
|
20 |
|
public function getOrigins() |
103
|
|
|
{ |
104
|
20 |
|
return $this->origins; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @param string[] $origins |
109
|
|
|
*/ |
110
|
8 |
|
public function setOrigins(array $origins) |
111
|
|
|
{ |
112
|
8 |
|
$this->origins = []; |
113
|
8 |
|
$this->addOrigins($origins); |
114
|
8 |
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @param string[] $origins |
118
|
|
|
*/ |
119
|
8 |
|
public function addOrigins(array $origins) |
120
|
|
|
{ |
121
|
8 |
|
foreach ($origins as $origin) { |
122
|
8 |
|
$this->addOrigin($origin); |
123
|
|
|
} |
124
|
8 |
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @param string $origin |
128
|
|
|
* |
129
|
|
|
* @return bool |
130
|
|
|
*/ |
131
|
16 |
|
public function hasOrigin($origin) |
132
|
|
|
{ |
133
|
16 |
|
return in_array($origin, $this->origins, true); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* @param string $origin |
138
|
|
|
*/ |
139
|
16 |
|
public function addOrigin($origin) |
140
|
|
|
{ |
141
|
16 |
|
if (!$this->hasOrigin($origin)) { |
142
|
16 |
|
$this->origins[] = $origin; |
143
|
|
|
} |
144
|
16 |
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* @param string $origin |
148
|
|
|
*/ |
149
|
4 |
|
public function removeOrigin($origin) |
150
|
|
|
{ |
151
|
4 |
|
unset($this->origins[array_search($origin, $this->origins, true)]); |
152
|
4 |
|
$this->origins = empty($this->origins) ? [] : array_values($this->origins); |
153
|
4 |
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* @return bool |
157
|
|
|
*/ |
158
|
20 |
|
public function hasDestinations() |
159
|
|
|
{ |
160
|
20 |
|
return !empty($this->destinations); |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* @return string[] |
165
|
|
|
*/ |
166
|
20 |
|
public function getDestinations() |
167
|
|
|
{ |
168
|
20 |
|
return $this->destinations; |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* @param string[] $destinations |
173
|
|
|
*/ |
174
|
8 |
|
public function setDestinations(array $destinations) |
175
|
|
|
{ |
176
|
8 |
|
$this->destinations = []; |
177
|
8 |
|
$this->addDestinations($destinations); |
178
|
8 |
|
} |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* @param string[] $destinations |
182
|
|
|
*/ |
183
|
8 |
|
public function addDestinations(array $destinations) |
184
|
|
|
{ |
185
|
8 |
|
foreach ($destinations as $destination) { |
186
|
8 |
|
$this->addDestination($destination); |
187
|
|
|
} |
188
|
8 |
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* @param string $destination |
192
|
|
|
* |
193
|
|
|
* @return bool |
194
|
|
|
*/ |
195
|
16 |
|
public function hasDestination($destination) |
196
|
|
|
{ |
197
|
16 |
|
return in_array($destination, $this->destinations, true); |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
* @param string $destination |
202
|
|
|
*/ |
203
|
16 |
|
public function addDestination($destination) |
204
|
|
|
{ |
205
|
16 |
|
if (!$this->hasDestination($destination)) { |
206
|
16 |
|
$this->destinations[] = $destination; |
207
|
|
|
} |
208
|
16 |
|
} |
209
|
|
|
|
210
|
|
|
/** |
211
|
|
|
* @param string $destination |
212
|
|
|
*/ |
213
|
4 |
|
public function removeDestination($destination) |
214
|
|
|
{ |
215
|
4 |
|
unset($this->destinations[array_search($destination, $this->destinations, true)]); |
216
|
4 |
|
$this->destinations = empty($this->destinations) ? [] : array_values($this->destinations); |
217
|
4 |
|
} |
218
|
|
|
|
219
|
|
|
/** |
220
|
|
|
* @return bool |
221
|
|
|
*/ |
222
|
20 |
|
public function hasRows() |
223
|
|
|
{ |
224
|
20 |
|
return !empty($this->rows); |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
/** |
228
|
|
|
* @return DistanceMatrixRow[] |
229
|
|
|
*/ |
230
|
20 |
|
public function getRows() |
231
|
|
|
{ |
232
|
20 |
|
return $this->rows; |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
/** |
236
|
|
|
* @param DistanceMatrixRow[] $rows |
237
|
|
|
*/ |
238
|
8 |
|
public function setRows(array $rows) |
239
|
|
|
{ |
240
|
8 |
|
$this->rows = []; |
241
|
8 |
|
$this->addRows($rows); |
242
|
8 |
|
} |
243
|
|
|
|
244
|
|
|
/** |
245
|
|
|
* @param DistanceMatrixRow[] $rows |
246
|
|
|
*/ |
247
|
8 |
|
public function addRows(array $rows) |
248
|
|
|
{ |
249
|
8 |
|
foreach ($rows as $row) { |
250
|
8 |
|
$this->addRow($row); |
251
|
|
|
} |
252
|
8 |
|
} |
253
|
|
|
|
254
|
|
|
/** |
255
|
|
|
* @return bool |
256
|
|
|
*/ |
257
|
16 |
|
public function hasRow(DistanceMatrixRow $row) |
258
|
|
|
{ |
259
|
16 |
|
return in_array($row, $this->rows, true); |
260
|
|
|
} |
261
|
|
|
|
262
|
16 |
|
public function addRow(DistanceMatrixRow $row) |
263
|
|
|
{ |
264
|
16 |
|
if (!$this->hasRow($row)) { |
265
|
16 |
|
$this->rows[] = $row; |
266
|
|
|
} |
267
|
16 |
|
} |
268
|
|
|
|
269
|
4 |
|
public function removeRow(DistanceMatrixRow $row) |
270
|
|
|
{ |
271
|
4 |
|
unset($this->rows[array_search($row, $this->rows, true)]); |
272
|
4 |
|
$this->rows = empty($this->rows) ? [] : array_values($this->rows); |
273
|
4 |
|
} |
274
|
|
|
} |
275
|
|
|
|