|
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\MaxMind\MaxMind; |
|
14
|
|
|
use Http\Client\HttpClient; |
|
15
|
|
|
use Http\Discovery\HttpClientDiscovery; |
|
16
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver; |
|
17
|
|
|
|
|
18
|
|
|
final class MaxMindFactory extends AbstractFactory |
|
19
|
|
|
{ |
|
20
|
|
|
protected static $dependencies = [ |
|
21
|
|
|
['requiredClass' => MaxMind::class, 'packageName' => 'geocoder-php/maxmind-provider'], |
|
22
|
|
|
]; |
|
23
|
|
|
|
|
24
|
|
|
protected function getProvider(array $config) |
|
25
|
|
|
{ |
|
26
|
|
|
$httplug = $config['httplug_client'] ?: HttpClientDiscovery::find(); |
|
27
|
|
|
|
|
28
|
|
|
return new MaxMind($httplug, $config['api_key'], $config['endpoint']); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
protected static function configureOptionResolver(OptionsResolver $resolver) |
|
32
|
|
|
{ |
|
33
|
|
|
$resolver->setDefaults([ |
|
34
|
|
|
'httplug_client' => null, |
|
35
|
|
|
'endpoint' => MaxMind::CITY_EXTENDED_SERVICE, |
|
36
|
|
|
]); |
|
37
|
|
|
|
|
38
|
|
|
$resolver->setRequired('api_key'); |
|
39
|
|
|
$resolver->setAllowedTypes('httplug_client', [HttpClient::class, 'null']); |
|
40
|
|
|
$resolver->setAllowedTypes('api_key', ['string']); |
|
41
|
|
|
$resolver->setAllowedValues('endpoint', [MaxMind::CITY_EXTENDED_SERVICE, MaxMind::OMNI_SERVICE]); |
|
42
|
|
|
} |
|
43
|
|
|
} |
|
44
|
|
|
|