|
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\Place\Autocomplete\Response; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @author GeLo <[email protected]> |
|
16
|
|
|
*/ |
|
17
|
|
|
class PlaceAutocompletePrediction |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* @var string|null |
|
21
|
|
|
*/ |
|
22
|
|
|
private $placeId; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @var string|null |
|
26
|
|
|
*/ |
|
27
|
|
|
private $description; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @var string[] |
|
31
|
|
|
*/ |
|
32
|
|
|
private $types = []; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @var PlaceAutocompleteTerm[] |
|
36
|
|
|
*/ |
|
37
|
|
|
private $terms = []; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @var PlaceAutocompleteMatch[] |
|
41
|
|
|
*/ |
|
42
|
|
|
private $matches = []; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @return bool |
|
46
|
|
|
*/ |
|
47
|
|
|
public function hasPlaceId() |
|
48
|
|
|
{ |
|
49
|
|
|
return $this->placeId !== null; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @return string|null |
|
54
|
|
|
*/ |
|
55
|
|
|
public function getPlaceId() |
|
56
|
|
|
{ |
|
57
|
|
|
return $this->placeId; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @param string|null $placeId |
|
62
|
|
|
*/ |
|
63
|
|
|
public function setPlaceId($placeId) |
|
64
|
|
|
{ |
|
65
|
|
|
$this->placeId = $placeId; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @return bool |
|
70
|
|
|
*/ |
|
71
|
|
|
public function hasDescription() |
|
72
|
|
|
{ |
|
73
|
|
|
return $this->description !== null; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @return string|null |
|
78
|
|
|
*/ |
|
79
|
|
|
public function getDescription() |
|
80
|
|
|
{ |
|
81
|
|
|
return $this->description; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* @param string|null $description |
|
86
|
|
|
*/ |
|
87
|
|
|
public function setDescription($description) |
|
88
|
|
|
{ |
|
89
|
|
|
$this->description = $description; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* @return bool |
|
94
|
|
|
*/ |
|
95
|
|
|
public function hasTypes() |
|
96
|
|
|
{ |
|
97
|
|
|
return !empty($this->types); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* @return string[] |
|
102
|
|
|
*/ |
|
103
|
|
|
public function getTypes() |
|
104
|
|
|
{ |
|
105
|
|
|
return $this->types; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* @param string[] $types |
|
110
|
|
|
*/ |
|
111
|
|
|
public function setTypes(array $types) |
|
112
|
|
|
{ |
|
113
|
|
|
$this->types = []; |
|
114
|
|
|
$this->addTypes($types); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* @param string[] $types |
|
119
|
|
|
*/ |
|
120
|
|
|
public function addTypes(array $types) |
|
121
|
|
|
{ |
|
122
|
|
|
foreach ($types as $type) { |
|
123
|
|
|
$this->addType($type); |
|
124
|
|
|
} |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* @param string $type |
|
129
|
|
|
* |
|
130
|
|
|
* @return bool |
|
131
|
|
|
*/ |
|
132
|
|
|
public function hasType($type) |
|
133
|
|
|
{ |
|
134
|
|
|
return in_array($type, $this->types, true); |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* @param string $type |
|
139
|
|
|
*/ |
|
140
|
|
|
public function addType($type) |
|
141
|
|
|
{ |
|
142
|
|
|
if (!$this->hasType($type)) { |
|
143
|
|
|
$this->types[] = $type; |
|
144
|
|
|
} |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
/** |
|
148
|
|
|
* @param string $type |
|
149
|
|
|
*/ |
|
150
|
|
|
public function removeType($type) |
|
151
|
|
|
{ |
|
152
|
|
|
unset($this->types[array_search($type, $this->types, true)]); |
|
153
|
|
|
$this->types = array_values($this->types); |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
/** |
|
157
|
|
|
* @return bool |
|
158
|
|
|
*/ |
|
159
|
|
|
public function hasTerms() |
|
160
|
|
|
{ |
|
161
|
|
|
return !empty($this->terms); |
|
162
|
|
|
} |
|
163
|
|
|
|
|
164
|
|
|
/** |
|
165
|
|
|
* @return PlaceAutocompleteTerm[] |
|
166
|
|
|
*/ |
|
167
|
|
|
public function getTerms() |
|
168
|
|
|
{ |
|
169
|
|
|
return $this->terms; |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
/** |
|
173
|
|
|
* @param PlaceAutocompleteTerm[] $terms |
|
174
|
|
|
*/ |
|
175
|
|
|
public function setTerms(array $terms) |
|
176
|
|
|
{ |
|
177
|
|
|
$this->terms = []; |
|
178
|
|
|
$this->addTerms($terms); |
|
179
|
|
|
} |
|
180
|
|
|
|
|
181
|
|
|
/** |
|
182
|
|
|
* @param PlaceAutocompleteTerm[] $terms |
|
183
|
|
|
*/ |
|
184
|
|
|
public function addTerms(array $terms) |
|
185
|
|
|
{ |
|
186
|
|
|
foreach ($terms as $term) { |
|
187
|
|
|
$this->addTerm($term); |
|
188
|
|
|
} |
|
189
|
|
|
} |
|
190
|
|
|
|
|
191
|
|
|
/** |
|
192
|
|
|
* @param PlaceAutocompleteTerm $term |
|
193
|
|
|
* |
|
194
|
|
|
* @return bool |
|
195
|
|
|
*/ |
|
196
|
|
|
public function hasTerm(PlaceAutocompleteTerm $term) |
|
197
|
|
|
{ |
|
198
|
|
|
return in_array($term, $this->terms, true); |
|
199
|
|
|
} |
|
200
|
|
|
|
|
201
|
|
|
/** |
|
202
|
|
|
* @param PlaceAutocompleteTerm $term |
|
203
|
|
|
*/ |
|
204
|
|
|
public function addTerm(PlaceAutocompleteTerm $term) |
|
205
|
|
|
{ |
|
206
|
|
|
if (!$this->hasTerm($term)) { |
|
207
|
|
|
$this->terms[] = $term; |
|
208
|
|
|
} |
|
209
|
|
|
} |
|
210
|
|
|
|
|
211
|
|
|
/** |
|
212
|
|
|
* @param PlaceAutocompleteTerm $term |
|
213
|
|
|
*/ |
|
214
|
|
|
public function removeTerm(PlaceAutocompleteTerm $term) |
|
215
|
|
|
{ |
|
216
|
|
|
unset($this->terms[array_search($term, $this->terms, true)]); |
|
217
|
|
|
$this->terms = array_values($this->terms); |
|
218
|
|
|
} |
|
219
|
|
|
|
|
220
|
|
|
/** |
|
221
|
|
|
* @return bool |
|
222
|
|
|
*/ |
|
223
|
|
|
public function hasMatches() |
|
224
|
|
|
{ |
|
225
|
|
|
return !empty($this->matches); |
|
226
|
|
|
} |
|
227
|
|
|
|
|
228
|
|
|
/** |
|
229
|
|
|
* @return PlaceAutocompleteMatch[] |
|
230
|
|
|
*/ |
|
231
|
|
|
public function getMatches() |
|
232
|
|
|
{ |
|
233
|
|
|
return $this->matches; |
|
234
|
|
|
} |
|
235
|
|
|
|
|
236
|
|
|
/** |
|
237
|
|
|
* @param PlaceAutocompleteMatch[] $matches |
|
238
|
|
|
*/ |
|
239
|
|
|
public function setMatches(array $matches) |
|
240
|
|
|
{ |
|
241
|
|
|
$this->matches = []; |
|
242
|
|
|
$this->addMatches($matches); |
|
243
|
|
|
} |
|
244
|
|
|
|
|
245
|
|
|
/** |
|
246
|
|
|
* @param PlaceAutocompleteMatch[] $matches |
|
247
|
|
|
*/ |
|
248
|
|
|
public function addMatches(array $matches) |
|
249
|
|
|
{ |
|
250
|
|
|
foreach ($matches as $match) { |
|
251
|
|
|
$this->addMatch($match); |
|
252
|
|
|
} |
|
253
|
|
|
} |
|
254
|
|
|
|
|
255
|
|
|
/** |
|
256
|
|
|
* @param PlaceAutocompleteMatch $match |
|
257
|
|
|
* |
|
258
|
|
|
* @return bool |
|
259
|
|
|
*/ |
|
260
|
|
|
public function hasMatch(PlaceAutocompleteMatch $match) |
|
261
|
|
|
{ |
|
262
|
|
|
return in_array($match, $this->matches, true); |
|
263
|
|
|
} |
|
264
|
|
|
|
|
265
|
|
|
/** |
|
266
|
|
|
* @param PlaceAutocompleteMatch $match |
|
267
|
|
|
*/ |
|
268
|
|
|
public function addMatch(PlaceAutocompleteMatch $match) |
|
269
|
|
|
{ |
|
270
|
|
|
if (!$this->hasMatch($match)) { |
|
271
|
|
|
$this->matches[] = $match; |
|
272
|
|
|
} |
|
273
|
|
|
} |
|
274
|
|
|
|
|
275
|
|
|
/** |
|
276
|
|
|
* @param PlaceAutocompleteMatch $match |
|
277
|
|
|
*/ |
|
278
|
|
|
public function removeMatch(PlaceAutocompleteMatch $match) |
|
279
|
|
|
{ |
|
280
|
|
|
unset($this->matches[array_search($match, $this->matches, true)]); |
|
281
|
|
|
$this->matches = array_values($this->matches); |
|
282
|
|
|
} |
|
283
|
|
|
} |
|
284
|
|
|
|