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\Place; |
13
|
|
|
|
14
|
|
|
use Ivory\GoogleMap\Base\Bound; |
15
|
|
|
use Ivory\GoogleMap\Utility\VariableAwareInterface; |
16
|
|
|
use Ivory\GoogleMap\Utility\VariableAwareTrait; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @author GeLo <[email protected]> |
20
|
|
|
*/ |
21
|
|
|
class Autocomplete implements VariableAwareInterface |
22
|
|
|
{ |
23
|
|
|
use VariableAwareTrait; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var string |
27
|
|
|
*/ |
28
|
|
|
private $inputId = 'place_input'; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var Bound|null |
32
|
|
|
*/ |
33
|
|
|
private $bound; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var string[] |
37
|
|
|
*/ |
38
|
|
|
private $types = []; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var array |
42
|
|
|
*/ |
43
|
|
|
private $componentRestrictions = []; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @var string |
47
|
|
|
*/ |
48
|
|
|
private $value; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @var string[] |
52
|
|
|
*/ |
53
|
|
|
private $inputAttributes = []; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @var string[] |
57
|
|
|
*/ |
58
|
|
|
private $libraries = []; |
59
|
|
|
|
60
|
|
|
public function __construct() |
61
|
|
|
{ |
62
|
|
|
$this->setVariablePrefix('place_autocomplete'); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @return string |
67
|
|
|
*/ |
68
|
|
|
public function getHtmlId() |
69
|
|
|
{ |
70
|
|
|
return $this->inputId; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @param string $inputId |
75
|
|
|
*/ |
76
|
|
|
public function setInputId($inputId) |
77
|
|
|
{ |
78
|
|
|
$this->inputId = $inputId; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @return bool |
83
|
|
|
*/ |
84
|
|
|
public function hasBound() |
85
|
|
|
{ |
86
|
|
|
return $this->bound !== null; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @return Bound|null |
91
|
|
|
*/ |
92
|
|
|
public function getBound() |
93
|
|
|
{ |
94
|
|
|
return $this->bound; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @param Bound|null $bound |
99
|
|
|
*/ |
100
|
|
|
public function setBound(Bound $bound = null) |
101
|
|
|
{ |
102
|
|
|
$this->bound = $bound; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @return bool |
107
|
|
|
*/ |
108
|
|
|
public function hasTypes() |
109
|
|
|
{ |
110
|
|
|
return !empty($this->types); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @return string[] |
115
|
|
|
*/ |
116
|
|
|
public function getTypes() |
117
|
|
|
{ |
118
|
|
|
return $this->types; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @param string[] $types |
123
|
|
|
*/ |
124
|
|
|
public function setTypes(array $types) |
125
|
|
|
{ |
126
|
|
|
$this->types = []; |
127
|
|
|
$this->addTypes($types); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @param string[] $types |
132
|
|
|
*/ |
133
|
|
|
public function addTypes(array $types) |
134
|
|
|
{ |
135
|
|
|
foreach ($types as $type) { |
136
|
|
|
$this->addType($type); |
137
|
|
|
} |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* @param string $type |
142
|
|
|
* |
143
|
|
|
* @return bool |
144
|
|
|
*/ |
145
|
|
|
public function hasType($type) |
146
|
|
|
{ |
147
|
|
|
return in_array($type, $this->types, true); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* @param string $type |
152
|
|
|
*/ |
153
|
|
|
public function addType($type) |
154
|
|
|
{ |
155
|
|
|
if (!$this->hasType($type)) { |
156
|
|
|
$this->types[] = $type; |
157
|
|
|
} |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* @param string $type |
162
|
|
|
*/ |
163
|
|
|
public function removeType($type) |
164
|
|
|
{ |
165
|
|
|
unset($this->types[array_search($type, $this->types, true)]); |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* @return bool |
170
|
|
|
*/ |
171
|
|
|
public function hasComponentRestrictions() |
172
|
|
|
{ |
173
|
|
|
return !empty($this->componentRestrictions); |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* @return string[] |
178
|
|
|
*/ |
179
|
|
|
public function getComponentRestrictions() |
180
|
|
|
{ |
181
|
|
|
return $this->componentRestrictions; |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* @param string[] $componentRestrictions |
186
|
|
|
*/ |
187
|
|
|
public function setComponentRestrictions(array $componentRestrictions) |
188
|
|
|
{ |
189
|
|
|
$this->componentRestrictions = []; |
190
|
|
|
$this->addComponentRestrictions($componentRestrictions); |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
/** |
194
|
|
|
* @param string[] $componentRestrictions |
195
|
|
|
*/ |
196
|
|
|
public function addComponentRestrictions(array $componentRestrictions) |
197
|
|
|
{ |
198
|
|
|
foreach ($componentRestrictions as $type => $value) { |
199
|
|
|
$this->setComponentRestriction($type, $value); |
200
|
|
|
} |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
/** |
204
|
|
|
* @param string $type |
205
|
|
|
* |
206
|
|
|
* @return bool |
207
|
|
|
*/ |
208
|
|
|
public function hasComponentRestriction($type) |
209
|
|
|
{ |
210
|
|
|
return isset($this->componentRestrictions[$type]); |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
/** |
214
|
|
|
* @param string $type |
215
|
|
|
* |
216
|
|
|
* @return string |
217
|
|
|
*/ |
218
|
|
|
public function getComponentRestriction($type) |
219
|
|
|
{ |
220
|
|
|
return $this->hasComponentRestriction($type) ? $this->componentRestrictions[$type] : null; |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
/** |
224
|
|
|
* @param string $type |
225
|
|
|
* @param string $value |
226
|
|
|
*/ |
227
|
|
|
public function setComponentRestriction($type, $value) |
228
|
|
|
{ |
229
|
|
|
$this->componentRestrictions[$type] = $value; |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
/** |
233
|
|
|
* @param string $type |
234
|
|
|
*/ |
235
|
|
|
public function removeComponentRestriction($type) |
236
|
|
|
{ |
237
|
|
|
unset($this->componentRestrictions[$type]); |
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
/** |
241
|
|
|
* @return bool |
242
|
|
|
*/ |
243
|
|
|
public function hasValue() |
244
|
|
|
{ |
245
|
|
|
return $this->value !== null; |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
/** |
249
|
|
|
* @return string|null |
250
|
|
|
*/ |
251
|
|
|
public function getValue() |
252
|
|
|
{ |
253
|
|
|
return $this->value; |
254
|
|
|
} |
255
|
|
|
|
256
|
|
|
/** |
257
|
|
|
* @param string|null $value |
258
|
|
|
*/ |
259
|
|
|
public function setValue($value = null) |
260
|
|
|
{ |
261
|
|
|
$this->value = $value; |
262
|
|
|
} |
263
|
|
|
|
264
|
|
|
/** |
265
|
|
|
* @return bool |
266
|
|
|
*/ |
267
|
|
|
public function hasInputAttributes() |
268
|
|
|
{ |
269
|
|
|
return !empty($this->inputAttributes); |
270
|
|
|
} |
271
|
|
|
|
272
|
|
|
/** |
273
|
|
|
* @return string[] |
274
|
|
|
*/ |
275
|
|
|
public function getInputAttributes() |
276
|
|
|
{ |
277
|
|
|
return $this->inputAttributes; |
278
|
|
|
} |
279
|
|
|
|
280
|
|
|
/** |
281
|
|
|
* @param string[] $inputAttributes |
282
|
|
|
*/ |
283
|
|
|
public function setInputAttributes(array $inputAttributes) |
284
|
|
|
{ |
285
|
|
|
$this->inputAttributes = []; |
286
|
|
|
$this->addInputAttributes($inputAttributes); |
287
|
|
|
} |
288
|
|
|
|
289
|
|
|
/** |
290
|
|
|
* @param string[] $inputAttributes |
291
|
|
|
*/ |
292
|
|
|
public function addInputAttributes(array $inputAttributes) |
293
|
|
|
{ |
294
|
|
|
foreach ($inputAttributes as $name => $value) { |
295
|
|
|
$this->setInputAttribute($name, $value); |
296
|
|
|
} |
297
|
|
|
} |
298
|
|
|
|
299
|
|
|
/** |
300
|
|
|
* @param string $name |
301
|
|
|
* |
302
|
|
|
* @return bool |
303
|
|
|
*/ |
304
|
|
|
public function hasInputAttribute($name) |
305
|
|
|
{ |
306
|
|
|
return isset($this->inputAttributes[$name]); |
307
|
|
|
} |
308
|
|
|
|
309
|
|
|
/** |
310
|
|
|
* @param string $name |
311
|
|
|
* |
312
|
|
|
* @return string|null |
313
|
|
|
*/ |
314
|
|
|
public function getInputAttribute($name) |
315
|
|
|
{ |
316
|
|
|
return $this->hasInputAttribute($name) ? $this->inputAttributes[$name] : null; |
317
|
|
|
} |
318
|
|
|
|
319
|
|
|
/** |
320
|
|
|
* @param string $name |
321
|
|
|
* @param string $value |
322
|
|
|
*/ |
323
|
|
|
public function setInputAttribute($name, $value) |
324
|
|
|
{ |
325
|
|
|
$this->inputAttributes[$name] = $value; |
326
|
|
|
} |
327
|
|
|
|
328
|
|
|
/** |
329
|
|
|
* @param string $name |
330
|
|
|
*/ |
331
|
|
|
public function removeInputAttribute($name) |
332
|
|
|
{ |
333
|
|
|
unset($this->inputAttributes[$name]); |
334
|
|
|
} |
335
|
|
|
|
336
|
|
|
/** |
337
|
|
|
* @return bool |
338
|
|
|
*/ |
339
|
|
|
public function hasLibraries() |
340
|
|
|
{ |
341
|
|
|
return !empty($this->libraries); |
342
|
|
|
} |
343
|
|
|
|
344
|
|
|
/** |
345
|
|
|
* @return string[] |
346
|
|
|
*/ |
347
|
|
|
public function getLibraries() |
348
|
|
|
{ |
349
|
|
|
return $this->libraries; |
350
|
|
|
} |
351
|
|
|
|
352
|
|
|
/** |
353
|
|
|
* @param string[] $libraries |
354
|
|
|
*/ |
355
|
|
|
public function setLibraries(array $libraries) |
356
|
|
|
{ |
357
|
|
|
$this->libraries = []; |
358
|
|
|
$this->addLibraries($libraries); |
359
|
|
|
} |
360
|
|
|
|
361
|
|
|
/** |
362
|
|
|
* @param string[] $libraries |
363
|
|
|
*/ |
364
|
|
|
public function addLibraries(array $libraries) |
365
|
|
|
{ |
366
|
|
|
foreach ($libraries as $library) { |
367
|
|
|
$this->addLibrary($library); |
368
|
|
|
} |
369
|
|
|
} |
370
|
|
|
|
371
|
|
|
/** |
372
|
|
|
* @param string $library |
373
|
|
|
* |
374
|
|
|
* @return bool |
375
|
|
|
*/ |
376
|
|
|
public function hasLibrary($library) |
377
|
|
|
{ |
378
|
|
|
return in_array($library, $this->libraries, true); |
379
|
|
|
} |
380
|
|
|
|
381
|
|
|
/** |
382
|
|
|
* @param string $library |
383
|
|
|
*/ |
384
|
|
|
public function addLibrary($library) |
385
|
|
|
{ |
386
|
|
|
if (!$this->hasLibrary($library)) { |
387
|
|
|
$this->libraries[] = $library; |
388
|
|
|
} |
389
|
|
|
} |
390
|
|
|
|
391
|
|
|
/** |
392
|
|
|
* @param string $library |
393
|
|
|
*/ |
394
|
|
|
public function removeLibrary($library) |
395
|
|
|
{ |
396
|
|
|
unset($this->libraries[array_search($library, $this->libraries, true)]); |
397
|
|
|
} |
398
|
|
|
} |
399
|
|
|
|