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\Direction\Response; |
13
|
|
|
|
14
|
|
|
use Ivory\GoogleMap\Base\Bound; |
15
|
|
|
use Ivory\GoogleMap\Overlay\EncodedPolyline; |
16
|
|
|
use Ivory\GoogleMap\Service\Base\Fare; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @see http://code.google.com/apis/maps/documentation/javascript/reference.html#DirectionRoute |
20
|
|
|
* |
21
|
|
|
* @author GeLo <[email protected]> |
22
|
|
|
*/ |
23
|
|
|
class DirectionRoute |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @var Bound|null |
27
|
|
|
*/ |
28
|
|
|
private $bound; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var string|null |
32
|
|
|
*/ |
33
|
|
|
private $copyrights; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var DirectionLeg[] |
37
|
|
|
*/ |
38
|
|
|
private $legs = []; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var EncodedPolyline|null |
42
|
|
|
*/ |
43
|
|
|
private $overviewPolyline; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @var string|null |
47
|
|
|
*/ |
48
|
|
|
private $summary; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @var Fare|null |
52
|
|
|
*/ |
53
|
|
|
private $fare; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @var string[] |
57
|
|
|
*/ |
58
|
|
|
private $warnings = []; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @var int[] |
62
|
|
|
*/ |
63
|
|
|
private $waypointOrders = []; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @return bool |
67
|
|
|
*/ |
68
|
12 |
|
public function hasBound() |
69
|
|
|
{ |
70
|
12 |
|
return $this->bound !== null; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @return Bound|null |
75
|
|
|
*/ |
76
|
276 |
|
public function getBound() |
77
|
|
|
{ |
78
|
276 |
|
return $this->bound; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @param Bound|null $bound |
83
|
|
|
*/ |
84
|
8 |
|
public function setBound(Bound $bound = null) |
85
|
|
|
{ |
86
|
8 |
|
$this->bound = $bound; |
87
|
8 |
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @return bool |
91
|
|
|
*/ |
92
|
12 |
|
public function hasCopyrights() |
93
|
|
|
{ |
94
|
12 |
|
return $this->copyrights !== null; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @return string|null |
99
|
|
|
*/ |
100
|
276 |
|
public function getCopyrights() |
101
|
|
|
{ |
102
|
276 |
|
return $this->copyrights; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @param string|null $copyrights |
107
|
|
|
*/ |
108
|
8 |
|
public function setCopyrights($copyrights = null) |
109
|
|
|
{ |
110
|
8 |
|
$this->copyrights = $copyrights; |
111
|
8 |
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @return bool |
115
|
|
|
*/ |
116
|
20 |
|
public function hasLegs() |
117
|
|
|
{ |
118
|
20 |
|
return !empty($this->legs); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @return DirectionLeg[] |
123
|
|
|
*/ |
124
|
284 |
|
public function getLegs() |
125
|
|
|
{ |
126
|
284 |
|
return $this->legs; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @param DirectionLeg[] $legs |
131
|
|
|
*/ |
132
|
8 |
|
public function setLegs(array $legs) |
133
|
|
|
{ |
134
|
8 |
|
$this->legs = []; |
135
|
8 |
|
$this->addLegs($legs); |
136
|
8 |
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* @param DirectionLeg[] $legs |
140
|
|
|
*/ |
141
|
8 |
|
public function addLegs(array $legs) |
142
|
|
|
{ |
143
|
8 |
|
foreach ($legs as $leg) { |
144
|
8 |
|
$this->addLeg($leg); |
145
|
4 |
|
} |
146
|
8 |
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* @param DirectionLeg $leg |
150
|
|
|
* |
151
|
|
|
* @return bool |
152
|
|
|
*/ |
153
|
16 |
|
public function hasLeg(DirectionLeg $leg) |
154
|
|
|
{ |
155
|
16 |
|
return in_array($leg, $this->legs, true); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* @param DirectionLeg $leg |
160
|
|
|
*/ |
161
|
16 |
|
public function addLeg(DirectionLeg $leg) |
162
|
|
|
{ |
163
|
16 |
|
if (!$this->hasLeg($leg)) { |
164
|
16 |
|
$this->legs[] = $leg; |
165
|
8 |
|
} |
166
|
16 |
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* @param DirectionLeg $leg |
170
|
|
|
*/ |
171
|
4 |
|
public function removeLeg(DirectionLeg $leg) |
172
|
|
|
{ |
173
|
4 |
|
unset($this->legs[array_search($leg, $this->legs, true)]); |
174
|
4 |
|
$this->legs = empty($this->legs) ? [] : array_values($this->legs); |
175
|
4 |
|
} |
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* @return bool |
179
|
|
|
*/ |
180
|
12 |
|
public function hasOverviewPolyline() |
181
|
|
|
{ |
182
|
12 |
|
return $this->overviewPolyline !== null; |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* @return EncodedPolyline|null |
187
|
|
|
*/ |
188
|
276 |
|
public function getOverviewPolyline() |
189
|
|
|
{ |
190
|
276 |
|
return $this->overviewPolyline; |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
/** |
194
|
|
|
* @param EncodedPolyline|null $overviewPolyline |
195
|
|
|
*/ |
196
|
8 |
|
public function setOverviewPolyline(EncodedPolyline $overviewPolyline = null) |
197
|
|
|
{ |
198
|
8 |
|
$this->overviewPolyline = $overviewPolyline; |
199
|
8 |
|
} |
200
|
|
|
|
201
|
|
|
/** |
202
|
|
|
* @return bool |
203
|
|
|
*/ |
204
|
12 |
|
public function hasSummary() |
205
|
|
|
{ |
206
|
12 |
|
return $this->summary !== null; |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
/** |
210
|
|
|
* @return string|null |
211
|
|
|
*/ |
212
|
276 |
|
public function getSummary() |
213
|
|
|
{ |
214
|
276 |
|
return $this->summary; |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
/** |
218
|
|
|
* @param string|null $summary |
219
|
|
|
*/ |
220
|
8 |
|
public function setSummary($summary = null) |
221
|
|
|
{ |
222
|
8 |
|
$this->summary = $summary; |
223
|
8 |
|
} |
224
|
|
|
|
225
|
|
|
/** |
226
|
|
|
* @return bool |
227
|
|
|
*/ |
228
|
12 |
|
public function hasFare() |
229
|
|
|
{ |
230
|
12 |
|
return $this->fare !== null; |
231
|
|
|
} |
232
|
|
|
|
233
|
|
|
/** |
234
|
|
|
* @return Fare|null |
235
|
|
|
*/ |
236
|
276 |
|
public function getFare() |
237
|
|
|
{ |
238
|
276 |
|
return $this->fare; |
239
|
|
|
} |
240
|
|
|
|
241
|
|
|
/** |
242
|
|
|
* @param Fare|null $fare |
243
|
|
|
*/ |
244
|
8 |
|
public function setFare(Fare $fare = null) |
245
|
|
|
{ |
246
|
8 |
|
$this->fare = $fare; |
247
|
8 |
|
} |
248
|
|
|
|
249
|
|
|
/** |
250
|
|
|
* @return bool |
251
|
|
|
*/ |
252
|
20 |
|
public function hasWarnings() |
253
|
|
|
{ |
254
|
20 |
|
return !empty($this->warnings); |
255
|
|
|
} |
256
|
|
|
|
257
|
|
|
/** |
258
|
|
|
* @return string[] |
259
|
|
|
*/ |
260
|
284 |
|
public function getWarnings() |
261
|
|
|
{ |
262
|
284 |
|
return $this->warnings; |
263
|
|
|
} |
264
|
|
|
|
265
|
|
|
/** |
266
|
|
|
* @param string[] $warnings |
267
|
|
|
*/ |
268
|
8 |
|
public function setWarnings(array $warnings) |
269
|
|
|
{ |
270
|
8 |
|
$this->warnings = []; |
271
|
8 |
|
$this->addWarnings($warnings); |
272
|
8 |
|
} |
273
|
|
|
|
274
|
|
|
/** |
275
|
|
|
* @param string[] $warnings |
276
|
|
|
*/ |
277
|
8 |
|
public function addWarnings(array $warnings) |
278
|
|
|
{ |
279
|
8 |
|
foreach ($warnings as $warning) { |
280
|
8 |
|
$this->addWarning($warning); |
281
|
4 |
|
} |
282
|
8 |
|
} |
283
|
|
|
|
284
|
|
|
/** |
285
|
|
|
* @param $warning |
286
|
|
|
* |
287
|
|
|
* @return bool |
288
|
|
|
*/ |
289
|
16 |
|
public function hasWarning($warning) |
290
|
|
|
{ |
291
|
16 |
|
return in_array($warning, $this->warnings, true); |
292
|
|
|
} |
293
|
|
|
|
294
|
|
|
/** |
295
|
|
|
* @param string $warning |
296
|
|
|
*/ |
297
|
16 |
|
public function addWarning($warning) |
298
|
|
|
{ |
299
|
16 |
|
if (!$this->hasWarning($warning)) { |
300
|
16 |
|
$this->warnings[] = $warning; |
301
|
8 |
|
} |
302
|
16 |
|
} |
303
|
|
|
|
304
|
|
|
/** |
305
|
|
|
* @param string $warning |
306
|
|
|
*/ |
307
|
4 |
|
public function removeWarning($warning) |
308
|
|
|
{ |
309
|
4 |
|
unset($this->warnings[array_search($warning, $this->warnings, true)]); |
310
|
4 |
|
$this->warnings = empty($this->warnings) ? [] : array_values($this->warnings); |
311
|
4 |
|
} |
312
|
|
|
|
313
|
|
|
/** |
314
|
|
|
* @return bool |
315
|
|
|
*/ |
316
|
12 |
|
public function hasWaypointOrders() |
317
|
|
|
{ |
318
|
12 |
|
return !empty($this->waypointOrders); |
319
|
|
|
} |
320
|
|
|
|
321
|
|
|
/** |
322
|
|
|
* @return int[] |
323
|
|
|
*/ |
324
|
276 |
|
public function getWaypointOrders() |
325
|
|
|
{ |
326
|
276 |
|
return $this->waypointOrders; |
327
|
|
|
} |
328
|
|
|
|
329
|
|
|
/** |
330
|
|
|
* @param int[] $waypointOrders |
331
|
|
|
*/ |
332
|
4 |
|
public function setWaypointOrders(array $waypointOrders) |
333
|
|
|
{ |
334
|
4 |
|
$this->waypointOrders = []; |
335
|
4 |
|
$this->addWaypointOrders($waypointOrders); |
336
|
4 |
|
} |
337
|
|
|
|
338
|
|
|
/** |
339
|
|
|
* @param int[] $waypointOrders |
340
|
|
|
*/ |
341
|
4 |
|
public function addWaypointOrders(array $waypointOrders) |
342
|
|
|
{ |
343
|
4 |
|
$this->waypointOrders = []; |
344
|
|
|
|
345
|
4 |
|
foreach ($waypointOrders as $waypointOrder) { |
346
|
4 |
|
$this->addWaypointOrder($waypointOrder); |
347
|
2 |
|
} |
348
|
4 |
|
} |
349
|
|
|
|
350
|
|
|
/** |
351
|
|
|
* @param $waypointOrder |
352
|
|
|
* |
353
|
|
|
* @return bool |
354
|
|
|
*/ |
355
|
8 |
|
public function hasWaypointOrder($waypointOrder) |
356
|
|
|
{ |
357
|
8 |
|
return in_array($waypointOrder, $this->waypointOrders, true); |
358
|
|
|
} |
359
|
|
|
|
360
|
|
|
/** |
361
|
|
|
* @param int $waypointOrder |
362
|
|
|
*/ |
363
|
8 |
|
public function addWaypointOrder($waypointOrder) |
364
|
|
|
{ |
365
|
8 |
|
$this->waypointOrders[] = $waypointOrder; |
366
|
8 |
|
} |
367
|
|
|
} |
368
|
|
|
|