1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the BazingaGeocoderBundle package. |
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
6
|
|
|
* file that was distributed with this source code. |
7
|
|
|
* |
8
|
|
|
* @license MIT License |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Bazinga\GeocoderBundle\ProviderFactory; |
12
|
|
|
|
13
|
|
|
use Geocoder\Provider\Mapbox\Mapbox; |
14
|
|
|
use Geocoder\Provider\Provider; |
15
|
|
|
use Http\Discovery\HttpClientDiscovery; |
16
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver; |
17
|
|
|
|
18
|
|
|
final class MapboxFactory extends AbstractFactory |
19
|
|
|
{ |
20
|
|
|
protected static $dependencies = [ |
21
|
|
|
['requiredClass' => Mapbox::class, 'packageName' => 'geocoder-php/mapbox-provider'], |
22
|
|
|
]; |
23
|
|
|
|
24
|
1 |
|
protected function getProvider(array $config): Provider |
25
|
|
|
{ |
26
|
1 |
|
$httplug = $config['httplug_client'] ?: HttpClientDiscovery::find(); |
27
|
|
|
|
28
|
1 |
|
return new Mapbox($httplug, $config['api_key'], $config['country'], $config['mode']); |
29
|
|
|
} |
30
|
|
|
|
31
|
1 |
|
protected static function configureOptionResolver(OptionsResolver $resolver) |
32
|
|
|
{ |
33
|
1 |
|
$resolver->setDefaults([ |
34
|
1 |
|
'httplug_client' => null, |
35
|
|
|
'country' => null, |
36
|
1 |
|
'mode' => Mapbox::GEOCODING_MODE_PLACES, |
37
|
|
|
]); |
38
|
|
|
|
39
|
1 |
|
$resolver->setRequired('api_key'); |
40
|
1 |
|
$resolver->setAllowedTypes('api_key', ['string']); |
41
|
1 |
|
$resolver->setAllowedTypes('mode', ['string']); |
42
|
1 |
|
$resolver->setAllowedTypes('httplug_client', ['object', 'null']); |
43
|
1 |
|
$resolver->setAllowedTypes('country', ['string', 'null']); |
44
|
1 |
|
} |
45
|
|
|
} |
46
|
|
|
|