1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the Ivory Google Map package. |
7
|
|
|
* |
8
|
|
|
* (c) Eric GELOEN <[email protected]> |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please read the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Ivory\GoogleMap\Service\Direction\Response; |
15
|
|
|
|
16
|
|
|
use Ivory\GoogleMap\Base\Coordinate; |
17
|
|
|
use Ivory\GoogleMap\Service\Base\Distance; |
18
|
|
|
use Ivory\GoogleMap\Service\Base\Duration; |
19
|
|
|
use Ivory\GoogleMap\Service\Base\Time; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @see http://code.google.com/apis/maps/documentation/javascript/reference.html#DirectionLeg |
23
|
|
|
*/ |
24
|
|
|
class DirectionLeg |
25
|
|
|
{ |
26
|
|
|
/** @var Distance|null */ |
27
|
|
|
private $distance; |
28
|
|
|
|
29
|
|
|
/** @var Duration|null */ |
30
|
|
|
private $duration; |
31
|
|
|
|
32
|
|
|
/** @var Duration|null */ |
33
|
|
|
private $durationInTraffic; |
34
|
|
|
|
35
|
|
|
/** @var Time|null */ |
36
|
|
|
private $arrivalTime; |
37
|
|
|
|
38
|
|
|
/** @var Time|null */ |
39
|
|
|
private $departureTime; |
40
|
|
|
|
41
|
|
|
/** @var string|null */ |
42
|
|
|
private $endAddress; |
43
|
|
|
|
44
|
|
|
/** @var Coordinate|null */ |
45
|
|
|
private $endLocation; |
46
|
|
|
|
47
|
|
|
/** @var string|null */ |
48
|
|
|
private $startAddress; |
49
|
|
|
|
50
|
|
|
/** @var Coordinate|null */ |
51
|
|
|
private $startLocation; |
52
|
|
|
|
53
|
|
|
/** @var DirectionStep[] */ |
54
|
|
|
private $steps = []; |
55
|
|
|
|
56
|
|
|
/** @var DirectionWaypoint[] */ |
57
|
|
|
private $viaWaypoints = []; |
58
|
|
|
|
59
|
3 |
|
public function hasDistance(): bool |
60
|
|
|
{ |
61
|
3 |
|
return null !== $this->distance; |
62
|
|
|
} |
63
|
|
|
|
64
|
3 |
|
public function getDistance(): ?Distance |
65
|
|
|
{ |
66
|
3 |
|
return $this->distance; |
67
|
|
|
} |
68
|
|
|
|
69
|
2 |
|
public function setDistance(Distance $distance = null): void |
70
|
|
|
{ |
71
|
2 |
|
$this->distance = $distance; |
72
|
2 |
|
} |
73
|
|
|
|
74
|
3 |
|
public function hasDuration(): bool |
75
|
|
|
{ |
76
|
3 |
|
return null !== $this->duration; |
77
|
|
|
} |
78
|
|
|
|
79
|
3 |
|
public function getDuration(): ?Duration |
80
|
|
|
{ |
81
|
3 |
|
return $this->duration; |
82
|
|
|
} |
83
|
|
|
|
84
|
2 |
|
public function setDuration(Duration $duration = null): void |
85
|
|
|
{ |
86
|
2 |
|
$this->duration = $duration; |
87
|
2 |
|
} |
88
|
|
|
|
89
|
3 |
|
public function hasDurationInTraffic(): bool |
90
|
|
|
{ |
91
|
3 |
|
return null !== $this->durationInTraffic; |
92
|
|
|
} |
93
|
|
|
|
94
|
3 |
|
public function getDurationInTraffic(): ?Duration |
95
|
|
|
{ |
96
|
3 |
|
return $this->durationInTraffic; |
97
|
|
|
} |
98
|
|
|
|
99
|
2 |
|
public function setDurationInTraffic(Duration $durationInTraffic = null): void |
100
|
|
|
{ |
101
|
2 |
|
$this->durationInTraffic = $durationInTraffic; |
102
|
2 |
|
} |
103
|
|
|
|
104
|
3 |
|
public function hasArrivalTime(): bool |
105
|
|
|
{ |
106
|
3 |
|
return null !== $this->arrivalTime; |
107
|
|
|
} |
108
|
|
|
|
109
|
3 |
|
public function getArrivalTime(): ?Time |
110
|
|
|
{ |
111
|
3 |
|
return $this->arrivalTime; |
112
|
|
|
} |
113
|
|
|
|
114
|
2 |
|
public function setArrivalTime(?Time $arrivalTime = null): void |
115
|
|
|
{ |
116
|
2 |
|
$this->arrivalTime = $arrivalTime; |
117
|
2 |
|
} |
118
|
|
|
|
119
|
3 |
|
public function hasDepartureTime(): bool |
120
|
|
|
{ |
121
|
3 |
|
return null !== $this->departureTime; |
122
|
|
|
} |
123
|
|
|
|
124
|
3 |
|
public function getDepartureTime(): ?Time |
125
|
|
|
{ |
126
|
3 |
|
return $this->departureTime; |
127
|
|
|
} |
128
|
|
|
|
129
|
2 |
|
public function setDepartureTime(?Time $departureTime = null): void |
130
|
|
|
{ |
131
|
2 |
|
$this->departureTime = $departureTime; |
132
|
2 |
|
} |
133
|
|
|
|
134
|
3 |
|
public function hasEndAddress(): bool |
135
|
|
|
{ |
136
|
3 |
|
return null !== $this->endAddress; |
137
|
|
|
} |
138
|
|
|
|
139
|
3 |
|
public function getEndAddress(): ?string |
140
|
|
|
{ |
141
|
3 |
|
return $this->endAddress; |
142
|
|
|
} |
143
|
|
|
|
144
|
2 |
|
public function setEndAddress(?string $endAddress = null): void |
145
|
|
|
{ |
146
|
2 |
|
$this->endAddress = $endAddress; |
147
|
2 |
|
} |
148
|
|
|
|
149
|
3 |
|
public function hasEndLocation(): bool |
150
|
|
|
{ |
151
|
3 |
|
return null !== $this->endLocation; |
152
|
|
|
} |
153
|
|
|
|
154
|
3 |
|
public function getEndLocation(): ?Coordinate |
155
|
|
|
{ |
156
|
3 |
|
return $this->endLocation; |
157
|
|
|
} |
158
|
|
|
|
159
|
2 |
|
public function setEndLocation(?Coordinate $endLocation = null): void |
160
|
|
|
{ |
161
|
2 |
|
$this->endLocation = $endLocation; |
162
|
2 |
|
} |
163
|
|
|
|
164
|
3 |
|
public function hasStartAddress(): bool |
165
|
|
|
{ |
166
|
3 |
|
return null !== $this->startAddress; |
167
|
|
|
} |
168
|
|
|
|
169
|
3 |
|
public function getStartAddress(): ?string |
170
|
|
|
{ |
171
|
3 |
|
return $this->startAddress; |
172
|
|
|
} |
173
|
|
|
|
174
|
2 |
|
public function setStartAddress(?string $startAddress = null): void |
175
|
|
|
{ |
176
|
2 |
|
$this->startAddress = $startAddress; |
177
|
2 |
|
} |
178
|
|
|
|
179
|
3 |
|
public function hasStartLocation(): bool |
180
|
|
|
{ |
181
|
3 |
|
return null !== $this->startLocation; |
182
|
|
|
} |
183
|
|
|
|
184
|
3 |
|
public function getStartLocation(): ?Coordinate |
185
|
|
|
{ |
186
|
3 |
|
return $this->startLocation; |
187
|
|
|
} |
188
|
|
|
|
189
|
2 |
|
public function setStartLocation(?Coordinate $startLocation = null): void |
190
|
|
|
{ |
191
|
2 |
|
$this->startLocation = $startLocation; |
192
|
2 |
|
} |
193
|
|
|
|
194
|
5 |
|
public function hasSteps(): bool |
195
|
|
|
{ |
196
|
5 |
|
return !empty($this->steps); |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
/** @return DirectionStep[] */ |
200
|
5 |
|
public function getSteps(): array |
201
|
|
|
{ |
202
|
5 |
|
return $this->steps; |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
/** @param DirectionStep[] $steps */ |
206
|
2 |
|
public function setSteps(array $steps): void |
207
|
|
|
{ |
208
|
2 |
|
$this->steps = []; |
209
|
2 |
|
$this->addSteps($steps); |
210
|
2 |
|
} |
211
|
|
|
|
212
|
|
|
/** @param DirectionStep[] $steps */ |
213
|
2 |
|
public function addSteps(array $steps): void |
214
|
|
|
{ |
215
|
2 |
|
foreach ($steps as $step) { |
216
|
2 |
|
$this->addStep($step); |
217
|
|
|
} |
218
|
2 |
|
} |
219
|
|
|
|
220
|
4 |
|
public function hasStep(DirectionStep $step): bool |
221
|
|
|
{ |
222
|
4 |
|
return in_array($step, $this->steps, true); |
223
|
|
|
} |
224
|
|
|
|
225
|
4 |
|
public function addStep(DirectionStep $step): void |
226
|
|
|
{ |
227
|
4 |
|
if (!$this->hasStep($step)) { |
228
|
4 |
|
$this->steps[] = $step; |
229
|
|
|
} |
230
|
4 |
|
} |
231
|
|
|
|
232
|
1 |
|
public function removeStep(DirectionStep $step): void |
233
|
|
|
{ |
234
|
1 |
|
unset($this->steps[array_search($step, $this->steps, true)]); |
235
|
1 |
|
$this->steps = empty($this->steps) ? [] : array_values($this->steps); |
236
|
1 |
|
} |
237
|
|
|
|
238
|
5 |
|
public function hasViaWaypoints(): bool |
239
|
|
|
{ |
240
|
5 |
|
return !empty($this->viaWaypoints); |
241
|
|
|
} |
242
|
|
|
|
243
|
|
|
/** @return DirectionWaypoint[] */ |
244
|
5 |
|
public function getViaWaypoints(): array |
245
|
|
|
{ |
246
|
5 |
|
return $this->viaWaypoints; |
247
|
|
|
} |
248
|
|
|
|
249
|
|
|
/** @param DirectionWaypoint[] $viaWaypoints */ |
250
|
2 |
|
public function setViaWaypoints(array $viaWaypoints): void |
251
|
|
|
{ |
252
|
2 |
|
$this->viaWaypoints = []; |
253
|
2 |
|
$this->addViaWaypoints($viaWaypoints); |
254
|
2 |
|
} |
255
|
|
|
|
256
|
|
|
/** @param DirectionWaypoint[] $viaWaypoints */ |
257
|
2 |
|
public function addViaWaypoints(array $viaWaypoints): void |
258
|
|
|
{ |
259
|
2 |
|
foreach ($viaWaypoints as $viaWaypoint) { |
260
|
2 |
|
$this->addViaWaypoint($viaWaypoint); |
261
|
|
|
} |
262
|
2 |
|
} |
263
|
|
|
|
264
|
4 |
|
public function hasViaWaypoint(DirectionWaypoint $viaWaypoint): bool |
265
|
|
|
{ |
266
|
4 |
|
return in_array($viaWaypoint, $this->viaWaypoints, true); |
267
|
|
|
} |
268
|
|
|
|
269
|
4 |
|
public function addViaWaypoint(DirectionWaypoint $viaWaypoint): void |
270
|
|
|
{ |
271
|
4 |
|
if (!$this->hasViaWaypoint($viaWaypoint)) { |
272
|
4 |
|
$this->viaWaypoints[] = $viaWaypoint; |
273
|
|
|
} |
274
|
4 |
|
} |
275
|
|
|
|
276
|
1 |
|
public function removeViaWaypoint(DirectionWaypoint $viaWaypoint): void |
277
|
|
|
{ |
278
|
1 |
|
unset($this->viaWaypoints[array_search($viaWaypoint, $this->viaWaypoints, true)]); |
279
|
1 |
|
$this->viaWaypoints = empty($this->viaWaypoints) ? [] : array_values($this->viaWaypoints); |
280
|
1 |
|
} |
281
|
|
|
} |
282
|
|
|
|