|
1
|
|
|
<?php namespace Arcanedev\GeoLocation\Google\Directions\Entities; |
|
2
|
|
|
|
|
3
|
|
|
use Arcanedev\GeoLocation\Entities\Coordinates\Position; |
|
4
|
|
|
use Arcanedev\GeoLocation\Entities\Measures\Distance; |
|
5
|
|
|
use Arcanedev\GeoLocation\Entities\Measures\Duration; |
|
6
|
|
|
use Arcanedev\GeoLocation\Traits\CanBeJsonable; |
|
7
|
|
|
use Illuminate\Contracts\Support\Arrayable; |
|
8
|
|
|
use Illuminate\Contracts\Support\Jsonable; |
|
9
|
|
|
use Illuminate\Support\Arr; |
|
10
|
|
|
use JsonSerializable; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Class Leg |
|
14
|
|
|
* |
|
15
|
|
|
* @package Arcanedev\GeoLocation\Google\Directions\Entities |
|
16
|
|
|
* @author ARCANEDEV <[email protected]> |
|
17
|
|
|
*/ |
|
18
|
|
|
class Leg implements Arrayable, Jsonable, JsonSerializable |
|
19
|
|
|
{ |
|
20
|
|
|
/* ----------------------------------------------------------------- |
|
21
|
|
|
| Traits |
|
22
|
|
|
| ----------------------------------------------------------------- |
|
23
|
|
|
*/ |
|
24
|
|
|
|
|
25
|
|
|
use CanBeJsonable; |
|
26
|
|
|
|
|
27
|
|
|
/* ----------------------------------------------------------------- |
|
28
|
|
|
| Properties |
|
29
|
|
|
| ----------------------------------------------------------------- |
|
30
|
|
|
*/ |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* The start address. |
|
34
|
|
|
* |
|
35
|
|
|
* @var string |
|
36
|
|
|
*/ |
|
37
|
|
|
protected $startAddress; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* The start location. |
|
41
|
|
|
* |
|
42
|
|
|
* @var \Arcanedev\GeoLocation\Contracts\Entities\Coordinates\Position |
|
43
|
|
|
*/ |
|
44
|
|
|
protected $startLocation; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* The end address |
|
48
|
|
|
* |
|
49
|
|
|
* @var string |
|
50
|
|
|
*/ |
|
51
|
|
|
protected $endAddress; |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* The end location. |
|
55
|
|
|
* |
|
56
|
|
|
* @var \Arcanedev\GeoLocation\Contracts\Entities\Coordinates\Position |
|
57
|
|
|
*/ |
|
58
|
|
|
protected $endLocation; |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* The distance (text + value). |
|
62
|
|
|
* |
|
63
|
|
|
* @var \Arcanedev\GeoLocation\Entities\Measures\Distance |
|
64
|
|
|
*/ |
|
65
|
|
|
protected $distance; |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* The duration (text + value). |
|
69
|
|
|
* |
|
70
|
|
|
* @var \Arcanedev\GeoLocation\Entities\Measures\Duration |
|
71
|
|
|
*/ |
|
72
|
|
|
protected $duration; |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* The steps collection. |
|
76
|
|
|
* |
|
77
|
|
|
* @var \Arcanedev\GeoLocation\Google\Directions\Entities\StepCollection |
|
78
|
|
|
*/ |
|
79
|
|
|
protected $steps; |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* The traffic speed entry. |
|
83
|
|
|
* |
|
84
|
|
|
* @var array |
|
85
|
|
|
*/ |
|
86
|
|
|
protected $trafficSpeedEntry; |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* The via waypoint. |
|
90
|
|
|
* |
|
91
|
|
|
* @var array |
|
92
|
|
|
*/ |
|
93
|
|
|
protected $viaWaypoint; |
|
94
|
|
|
|
|
95
|
|
|
/* ----------------------------------------------------------------- |
|
96
|
|
|
| Main Methods |
|
97
|
|
|
| ----------------------------------------------------------------- |
|
98
|
|
|
*/ |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* Leg constructor. |
|
102
|
|
|
* |
|
103
|
|
|
* @param array $data |
|
104
|
|
|
*/ |
|
105
|
21 |
|
public function __construct(array $data) |
|
106
|
|
|
{ |
|
107
|
21 |
|
$this->startAddress = Arr::get($data, 'start_address', ''); |
|
108
|
21 |
|
$this->startLocation = Position::createFromArray(Arr::get($data, 'start_location', ['lat' => 0, 'lng' => 0])); |
|
109
|
|
|
|
|
110
|
21 |
|
$this->endAddress = Arr::get($data, 'end_address', ''); |
|
111
|
21 |
|
$this->endLocation = Position::createFromArray(Arr::get($data, 'end_location', ['lat' => 0, 'lng' => 0])); |
|
112
|
|
|
|
|
113
|
21 |
|
$this->distance = Distance::makeFromArray(Arr::get($data, 'distance', ['text' => '', 'value' => 0])); |
|
114
|
21 |
|
$this->duration = Duration::makeFromArray(Arr::get($data, 'duration', ['text' => '', 'value' => 0])); |
|
115
|
|
|
|
|
116
|
21 |
|
$this->steps = StepCollection::load(Arr::get($data, 'steps', [])); |
|
117
|
|
|
|
|
118
|
21 |
|
$this->trafficSpeedEntry = Arr::get($data, 'traffic_speed_entry', []); |
|
|
|
|
|
|
119
|
21 |
|
$this->viaWaypoint = Arr::get($data, 'via_waypoint', []); |
|
|
|
|
|
|
120
|
21 |
|
} |
|
121
|
|
|
|
|
122
|
|
|
/* ----------------------------------------------------------------- |
|
123
|
|
|
| Getters & Setters |
|
124
|
|
|
| ----------------------------------------------------------------- |
|
125
|
|
|
*/ |
|
126
|
|
|
/** |
|
127
|
|
|
* @return string |
|
128
|
|
|
*/ |
|
129
|
9 |
|
public function startAddress() |
|
130
|
|
|
{ |
|
131
|
9 |
|
return $this->startAddress; |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
/** |
|
135
|
|
|
* @return \Arcanedev\GeoLocation\Contracts\Entities\Coordinates\Position |
|
136
|
|
|
*/ |
|
137
|
9 |
|
public function startLocation() |
|
138
|
|
|
{ |
|
139
|
9 |
|
return $this->startLocation; |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
/** |
|
143
|
|
|
* @return string |
|
144
|
|
|
*/ |
|
145
|
9 |
|
public function endAddress() |
|
146
|
|
|
{ |
|
147
|
9 |
|
return $this->endAddress; |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
/** |
|
151
|
|
|
* @return \Arcanedev\GeoLocation\Contracts\Entities\Coordinates\Position |
|
152
|
|
|
*/ |
|
153
|
9 |
|
public function endLocation() |
|
154
|
|
|
{ |
|
155
|
9 |
|
return $this->endLocation; |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
/** |
|
159
|
|
|
* Get the distance. |
|
160
|
|
|
* |
|
161
|
|
|
* @return \Arcanedev\GeoLocation\Entities\Measures\Distance |
|
162
|
|
|
*/ |
|
163
|
9 |
|
public function distance() |
|
164
|
|
|
{ |
|
165
|
9 |
|
return $this->distance; |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
/** |
|
169
|
|
|
* Get the duration. |
|
170
|
|
|
* |
|
171
|
|
|
* @return \Arcanedev\GeoLocation\Entities\Measures\Duration |
|
172
|
|
|
*/ |
|
173
|
9 |
|
public function duration() |
|
174
|
|
|
{ |
|
175
|
9 |
|
return $this->duration; |
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
|
|
/** |
|
179
|
|
|
* Get the step collection. |
|
180
|
|
|
* |
|
181
|
|
|
* @return \Arcanedev\GeoLocation\Google\Directions\Entities\StepCollection |
|
182
|
|
|
*/ |
|
183
|
9 |
|
public function steps() |
|
184
|
|
|
{ |
|
185
|
9 |
|
return $this->steps; |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
/** |
|
189
|
|
|
* Get the traffic speed entry. |
|
190
|
|
|
* |
|
191
|
|
|
* @return array |
|
192
|
|
|
*/ |
|
193
|
9 |
|
public function trafficSpeedEntry() |
|
194
|
|
|
{ |
|
195
|
9 |
|
return $this->trafficSpeedEntry; |
|
196
|
|
|
} |
|
197
|
|
|
|
|
198
|
|
|
/** |
|
199
|
|
|
* Get the via waypoint. |
|
200
|
|
|
* |
|
201
|
|
|
* @return array |
|
202
|
|
|
*/ |
|
203
|
9 |
|
public function viaWaypoint() |
|
204
|
|
|
{ |
|
205
|
9 |
|
return $this->viaWaypoint; |
|
206
|
|
|
} |
|
207
|
|
|
|
|
208
|
|
|
/* ----------------------------------------------------------------- |
|
209
|
|
|
| Main Methods |
|
210
|
|
|
| ----------------------------------------------------------------- |
|
211
|
|
|
*/ |
|
212
|
|
|
|
|
213
|
|
|
/** |
|
214
|
|
|
* Get the instance as an array. |
|
215
|
|
|
* |
|
216
|
|
|
* @return array |
|
217
|
|
|
*/ |
|
218
|
6 |
|
public function toArray() |
|
219
|
|
|
{ |
|
220
|
|
|
return [ |
|
221
|
6 |
|
'start_address' => $this->startAddress(), |
|
222
|
6 |
|
'start_location' => $this->startLocation()->toArray(), |
|
223
|
6 |
|
'end_address' => $this->endAddress(), |
|
224
|
6 |
|
'end_location' => $this->endLocation()->toArray(), |
|
225
|
6 |
|
'distance' => $this->distance()->toArray(), |
|
226
|
6 |
|
'duration' => $this->duration()->toArray(), |
|
227
|
6 |
|
'steps' => $this->steps()->toArray(), |
|
228
|
6 |
|
'traffic_speed_entry' => $this->trafficSpeedEntry(), |
|
229
|
6 |
|
'via_waypoint' => $this->viaWaypoint(), |
|
230
|
2 |
|
]; |
|
231
|
|
|
} |
|
232
|
|
|
} |
|
233
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..