Skip to content

Commit 1409e4f

Browse files
committed
add MapboxFactory
Remove useless use Add new line at end of file Add missing comma Fix packageName
1 parent 5ea8f24 commit 1409e4f

File tree

4 files changed

+56
-0
lines changed

4 files changed

+56
-0
lines changed

ProviderFactory/MapboxFactory.php

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

Tests/Functional/ProviderFactoryTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
use Geocoder\Provider\IpInfo\IpInfo;
3030
use Geocoder\Provider\IpInfoDb\IpInfoDb;
3131
use Geocoder\Provider\Ipstack\Ipstack;
32+
use Geocoder\Provider\Mapbox\Mapbox;
3233
use Geocoder\Provider\MapQuest\MapQuest;
3334
use Geocoder\Provider\Mapzen\Mapzen;
3435
use Geocoder\Provider\MaxMind\MaxMind;
@@ -74,6 +75,7 @@ public function getProviders()
7475
[IpInfo::class, ['acme']],
7576
[IpInfoDb::class, ['empty', 'acme']],
7677
[Ipstack::class, ['acme']],
78+
[Mapbox::class, ['acme']],
7779
[MapQuest::class, ['acme']],
7880
[Mapzen::class, ['acme']],
7981
[MaxMind::class, ['acme']],
Lines changed: 8 additions & 0 deletions
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\MapboxFactory
7+
options:
8+
api_key: 'bar'

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"doctrine/orm": "~2.3",
2525
"fzaninotto/faker": "^1.8",
2626
"geocoder-php/algolia-places-provider": "^0.1.1",
27+
"geocoder-php/mapbox-provider": "^1.0",
2728
"geocoder-php/arcgis-online-provider": "^4.0",
2829
"geocoder-php/bing-maps-provider": "^4.0",
2930
"geocoder-php/cache-provider": "^4.0",

0 commit comments

Comments
 (0)