Skip to content

Commit 30174c6

Browse files
authored
Merge pull request #309 from nassuf/feat/add_locationiq_provider
Add locationIQ provider
2 parents a051134 + 79257e0 commit 30174c6

File tree

5 files changed

+53
-0
lines changed

5 files changed

+53
-0
lines changed

ProviderFactory/LocationIQFactory.php

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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\LocationIQ\LocationIQ;
14+
use Geocoder\Provider\Provider;
15+
use Http\Discovery\HttpClientDiscovery;
16+
use Symfony\Component\OptionsResolver\OptionsResolver;
17+
18+
final class LocationIQFactory extends AbstractFactory
19+
{
20+
protected static $dependencies = [
21+
['requiredClass' => LocationIQ::class, 'packageName' => 'geocoder-php/locationiq-provider'],
22+
];
23+
24+
protected function getProvider(array $config): Provider
25+
{
26+
$httplug = $config['httplug_client'] ?: $this->httpClient ?? HttpClientDiscovery::find();
27+
28+
return new LocationIQ($httplug, $config['api_key']);
29+
}
30+
31+
protected static function configureOptionResolver(OptionsResolver $resolver)
32+
{
33+
$resolver->setDefaults([
34+
'httplug_client' => null,
35+
]);
36+
37+
$resolver->setAllowedTypes('httplug_client', ['object', 'null']);
38+
$resolver->setRequired(['api_key']);
39+
$resolver->setAllowedTypes('api_key', ['string']);
40+
}
41+
}

Resources/doc/services.md

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Here is a list of all provider factories and their options.
2727
| `Bazinga\GeocoderBundle\ProviderFactory\IpInfoFactory` | httplug_client
2828
| `Bazinga\GeocoderBundle\ProviderFactory\IpInfoDbFactory` | httplug_client, api_key, precision
2929
| `Bazinga\GeocoderBundle\ProviderFactory\IpstackFactory` | httplug_client, api_key
30+
| `Bazinga\GeocoderBundle\ProviderFactory\LocationIQFactory` | httplug_client, api_key
3031
| `Bazinga\GeocoderBundle\ProviderFactory\MapboxFactory` | httplug_client, api_key, country, mode
3132
| `Bazinga\GeocoderBundle\ProviderFactory\MapQuestFactory` | httplug_client, api_key, licensed
3233
| `Bazinga\GeocoderBundle\ProviderFactory\MapzenFactory` | httplug_client, api_key

Tests/Functional/ProviderFactoryTest.php

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
use Geocoder\Provider\IpInfo\IpInfo;
3131
use Geocoder\Provider\IpInfoDb\IpInfoDb;
3232
use Geocoder\Provider\Ipstack\Ipstack;
33+
use Geocoder\Provider\LocationIQ\LocationIQ;
3334
use Geocoder\Provider\Mapbox\Mapbox;
3435
use Geocoder\Provider\MapQuest\MapQuest;
3536
use Geocoder\Provider\Mapzen\Mapzen;
@@ -80,6 +81,7 @@ public function getProviders()
8081
yield [IpInfo::class, ['acme']];
8182
yield [IpInfoDb::class, ['empty', 'acme']];
8283
yield [Ipstack::class, ['acme']];
84+
yield [LocationIQ::class, ['acme']];
8385
yield [Mapbox::class, ['acme']];
8486
yield [MapQuest::class, ['acme']];
8587
if (class_exists(Mapzen::class)) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
bazinga_geocoder:
2+
profiling:
3+
enabled: false
4+
providers:
5+
acme:
6+
factory: Bazinga\GeocoderBundle\ProviderFactory\LocationIQFactory
7+
options:
8+
api_key: 'foo'

composer.json

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"geocoder-php/ip-info-db-provider": "^4.2",
4242
"geocoder-php/ip-info-provider": "^0.3",
4343
"geocoder-php/ipstack-provider": "^0.3",
44+
"geocoder-php/locationiq-provider": "^1.2",
4445
"geocoder-php/mapbox-provider": "^1.3",
4546
"geocoder-php/mapquest-provider": "^4.2",
4647
"geocoder-php/mapzen-provider": "^4.0",

0 commit comments

Comments
 (0)