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