forked from geocoder-php/BazingaGeocoderBundle
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNominatimFactory.php
More file actions
54 lines (44 loc) · 1.92 KB
/
NominatimFactory.php
File metadata and controls
54 lines (44 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
declare(strict_types=1);
/*
* This file is part of the BazingaGeocoderBundle package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/
namespace Bazinga\GeocoderBundle\ProviderFactory;
use Geocoder\Provider\Nominatim\Nominatim;
use Geocoder\Provider\Provider;
use Http\Discovery\Psr18ClientDiscovery;
use Psr\Http\Client\ClientInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
final class NominatimFactory extends AbstractFactory
{
protected static $dependencies = [
['requiredClass' => Nominatim::class, 'packageName' => 'geocoder-php/nominatim-provider'],
];
/**
* @param array{root_url: string, user_agent: string, http_client: ?ClientInterface, httplug_client: ?ClientInterface} $config
*/
protected function getProvider(array $config): Provider
{
$httpClient = $config['http_client'] ?? $config['httplug_client'] ?? $this->httpClient ?? Psr18ClientDiscovery::find();
return new Nominatim($httpClient, $config['root_url'], $config['user_agent']);
}
protected static function configureOptionResolver(OptionsResolver $resolver)
{
$resolver->setDefaults([
'httplug_client' => null,
'http_client' => null,
'root_url' => 'https://nominatim.openstreetmap.org',
'user_agent' => 'BazingaGeocoderBundle',
]);
$resolver->setAllowedTypes('httplug_client', ['object', 'null']);
$resolver->setAllowedTypes('http_client', ['object', 'null']);
$resolver->setAllowedTypes('root_url', ['string']);
$resolver->setAllowedTypes('user_agent', ['string']);
$resolver->setRequired('user_agent');
$resolver->setDeprecated('httplug_client', 'willdurand/geocoder-bundle', '5.19', 'The option "httplug_client" is deprecated, use "http_client" instead.');
}
}