Skip to content

Commit 88f7847

Browse files
markomitranicNyholm
authored andcommitted
Add Algolia provider factory (#247)
Add tests for Algolia factory fix typo
1 parent 87b0707 commit 88f7847

File tree

5 files changed

+61
-0
lines changed

5 files changed

+61
-0
lines changed

ProviderFactory/AlgoliaFactory.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is part of the BazingaGeocoderBundle package.
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*
10+
* @license MIT License
11+
*/
12+
13+
namespace Bazinga\GeocoderBundle\ProviderFactory;
14+
15+
use Geocoder\Provider\AlgoliaPlaces\AlgoliaPlaces;
16+
use Geocoder\Provider\Provider;
17+
use Http\Discovery\HttpClientDiscovery;
18+
use Symfony\Component\OptionsResolver\OptionsResolver;
19+
20+
final class AlgoliaFactory extends AbstractFactory
21+
{
22+
protected static $dependencies = [
23+
['requiredClass' => AlgoliaPlaces::class, 'packageName' => 'geocoder-php/algolia-places-provider'],
24+
];
25+
26+
protected function getProvider(array $config): Provider
27+
{
28+
$httplug = $config['httplug_client'] ?: HttpClientDiscovery::find();
29+
30+
return new AlgoliaPlaces($httplug, $config['api_key'], $config['app_id']);
31+
}
32+
33+
protected static function configureOptionResolver(OptionsResolver $resolver)
34+
{
35+
$resolver->setDefaults([
36+
'httplug_client' => null,
37+
'api_key' => null,
38+
'app_id' => null,
39+
]);
40+
41+
$resolver->setAllowedTypes('httplug_client', ['object', 'null']);
42+
$resolver->setAllowedTypes('api_key', ['string', 'null']);
43+
$resolver->setAllowedTypes('app_id', ['string', 'null']);
44+
}
45+
}

Resources/doc/services.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Here is a list of all provider factories and their options.
1010

1111
| Service | Options |
1212
| ------- | ------- |
13+
| `Bazinga\GeocoderBundle\ProviderFactory\AlgoliaPlaceFactory` | httplug_client, api_key, app_id
1314
| `Bazinga\GeocoderBundle\ProviderFactory\ArcGISOnlineFactory` | httplug_client, source_country
1415
| `Bazinga\GeocoderBundle\ProviderFactory\BingMapsFactory` | httplug_client, api_key
1516
| `Bazinga\GeocoderBundle\ProviderFactory\ChainFactory` | services

Tests/Functional/ProviderFactoryTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
namespace Bazinga\GeocoderBundle\Tests\Functional;
1414

1515
use Bazinga\GeocoderBundle\BazingaGeocoderBundle;
16+
use Geocoder\Provider\AlgoliaPlaces\AlgoliaPlaces;
1617
use Geocoder\Provider\ArcGISOnline\ArcGISOnline;
1718
use Geocoder\Provider\BingMaps\BingMaps;
1819
use Geocoder\Provider\Chain\Chain;
@@ -57,6 +58,7 @@ protected function getBundleClass()
5758
public function getProviders()
5859
{
5960
return [
61+
[AlgoliaPlaces::class, ['empty', 'acme']],
6062
[ArcGISOnline::class, ['empty', 'acme']],
6163
[BingMaps::class, ['acme']],
6264
[Chain::class, ['acme']],
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
bazinga_geocoder:
2+
profiling:
3+
enabled: false
4+
providers:
5+
empty:
6+
factory: Bazinga\GeocoderBundle\ProviderFactory\AlgoliaFactory
7+
8+
acme:
9+
factory: Bazinga\GeocoderBundle\ProviderFactory\AlgoliaFactory
10+
options:
11+
api_key: 'foo'
12+
app_id: 'bar'

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"require-dev": {
2323
"doctrine/cache": "~1.3",
2424
"doctrine/orm": "~2.3",
25+
"geocoder-php/algolia-places-provider": "^0.1.1",
2526
"geocoder-php/arcgis-online-provider": "^4.0",
2627
"geocoder-php/bing-maps-provider": "^4.0",
2728
"geocoder-php/cache-provider": "^4.0",

0 commit comments

Comments
 (0)