Skip to content

Commit

Permalink
Merge pull request #309 from nassuf/feat/add_locationiq_provider
Browse files Browse the repository at this point in the history
Add locationIQ provider
  • Loading branch information
norkunas authored May 4, 2021
2 parents a051134 + 79257e0 commit 30174c6
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 0 deletions.
41 changes: 41 additions & 0 deletions ProviderFactory/LocationIQFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

/*
* 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\LocationIQ\LocationIQ;
use Geocoder\Provider\Provider;
use Http\Discovery\HttpClientDiscovery;
use Symfony\Component\OptionsResolver\OptionsResolver;

final class LocationIQFactory extends AbstractFactory
{
protected static $dependencies = [
['requiredClass' => LocationIQ::class, 'packageName' => 'geocoder-php/locationiq-provider'],
];

protected function getProvider(array $config): Provider
{
$httplug = $config['httplug_client'] ?: $this->httpClient ?? HttpClientDiscovery::find();

return new LocationIQ($httplug, $config['api_key']);
}

protected static function configureOptionResolver(OptionsResolver $resolver)
{
$resolver->setDefaults([
'httplug_client' => null,
]);

$resolver->setAllowedTypes('httplug_client', ['object', 'null']);
$resolver->setRequired(['api_key']);
$resolver->setAllowedTypes('api_key', ['string']);
}
}
1 change: 1 addition & 0 deletions Resources/doc/services.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Here is a list of all provider factories and their options.
| `Bazinga\GeocoderBundle\ProviderFactory\IpInfoFactory` | httplug_client
| `Bazinga\GeocoderBundle\ProviderFactory\IpInfoDbFactory` | httplug_client, api_key, precision
| `Bazinga\GeocoderBundle\ProviderFactory\IpstackFactory` | httplug_client, api_key
| `Bazinga\GeocoderBundle\ProviderFactory\LocationIQFactory` | httplug_client, api_key
| `Bazinga\GeocoderBundle\ProviderFactory\MapboxFactory` | httplug_client, api_key, country, mode
| `Bazinga\GeocoderBundle\ProviderFactory\MapQuestFactory` | httplug_client, api_key, licensed
| `Bazinga\GeocoderBundle\ProviderFactory\MapzenFactory` | httplug_client, api_key
Expand Down
2 changes: 2 additions & 0 deletions Tests/Functional/ProviderFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use Geocoder\Provider\IpInfo\IpInfo;
use Geocoder\Provider\IpInfoDb\IpInfoDb;
use Geocoder\Provider\Ipstack\Ipstack;
use Geocoder\Provider\LocationIQ\LocationIQ;
use Geocoder\Provider\Mapbox\Mapbox;
use Geocoder\Provider\MapQuest\MapQuest;
use Geocoder\Provider\Mapzen\Mapzen;
Expand Down Expand Up @@ -80,6 +81,7 @@ public function getProviders()
yield [IpInfo::class, ['acme']];
yield [IpInfoDb::class, ['empty', 'acme']];
yield [Ipstack::class, ['acme']];
yield [LocationIQ::class, ['acme']];
yield [Mapbox::class, ['acme']];
yield [MapQuest::class, ['acme']];
if (class_exists(Mapzen::class)) {
Expand Down
8 changes: 8 additions & 0 deletions Tests/Functional/config/provider/locationiq.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
bazinga_geocoder:
profiling:
enabled: false
providers:
acme:
factory: Bazinga\GeocoderBundle\ProviderFactory\LocationIQFactory
options:
api_key: 'foo'
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"geocoder-php/ip-info-db-provider": "^4.2",
"geocoder-php/ip-info-provider": "^0.3",
"geocoder-php/ipstack-provider": "^0.3",
"geocoder-php/locationiq-provider": "^1.2",
"geocoder-php/mapbox-provider": "^1.3",
"geocoder-php/mapquest-provider": "^4.2",
"geocoder-php/mapzen-provider": "^4.0",
Expand Down

0 comments on commit 30174c6

Please sign in to comment.