-
Notifications
You must be signed in to change notification settings - Fork 110
/
Copy pathGeoIPsFactory.php
53 lines (43 loc) · 1.7 KB
/
GeoIPsFactory.php
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
<?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\GeoIPs\GeoIPs;
use Geocoder\Provider\Provider;
use Http\Client\HttpClient;
use Http\Discovery\HttpClientDiscovery;
use Symfony\Component\OptionsResolver\OptionsResolver;
/**
* @deprecated since 5.6, to be removed in 6.0. See https://github.com/geocoder-php/Geocoder/issues/965
*/
final class GeoIPsFactory extends AbstractFactory
{
protected static $dependencies = [
['requiredClass' => GeoIPs::class, 'packageName' => 'geocoder-php/geoips-provider'],
];
/**
* @param array{api_key: string, httplug_client: ?HttpClient} $config
*/
protected function getProvider(array $config): Provider
{
@trigger_error('Bazinga\GeocoderBundle\ProviderFactory\GeoIPsFactory is deprecated since 5.6, to be removed in 6.0. See https://github.com/geocoder-php/Geocoder/issues/965', E_USER_DEPRECATED);
$httplug = $config['httplug_client'] ?: $this->httpClient ?? HttpClientDiscovery::find();
assert($httplug instanceof HttpClient);
return new GeoIPs($httplug, $config['api_key']);
}
protected static function configureOptionResolver(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'httplug_client' => null,
]);
$resolver->setRequired('api_key');
$resolver->setAllowedTypes('httplug_client', [HttpClient::class, 'null']);
$resolver->setAllowedTypes('api_key', ['string']);
}
}