Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions ProviderFactory/AlgoliaPlacesFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?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\AlgoliaPlaces\AlgoliaPlaces;
use Geocoder\Provider\Provider;
use Http\Discovery\HttpClientDiscovery;
use Symfony\Component\OptionsResolver\OptionsResolver;

final class AlgoliaPlacesFactory extends AbstractFactory
{
protected static $dependencies = [
['requiredClass' => AlgoliaPlaces::class, 'packageName' => 'geocoder-php/algolia-place-provider'],
];

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

return new AlgoliaPlaces($httplug, $config['apiKey'], $config['appId']);
}

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

$resolver->setAllowedTypes('httplug_client', ['object', 'null']);
$resolver->setAllowedTypes('apiKey', ['string']);
Copy link

@tgalopin tgalopin Oct 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about using api_key and app_id instead to be consistent with the other factories?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

$resolver->setAllowedTypes('appId', ['string']);
}
}
1 change: 1 addition & 0 deletions Resources/doc/services.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Here is a list of all provider factories and their options.

| Service | Options |
| ------- | ------- |
| `Bazinga\GeocoderBundle\ProviderFactory\AlgoliaPlaceFactory` | httplug_client, apiKey, appId
| `Bazinga\GeocoderBundle\ProviderFactory\ArcGISOnlineFactory` | httplug_client, source_country
| `Bazinga\GeocoderBundle\ProviderFactory\BingMapsFactory` | httplug_client, api_key
| `Bazinga\GeocoderBundle\ProviderFactory\ChainFactory` | services
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"geocoder-php/plugin": "^1.0",
"symfony/framework-bundle": "^3.3 || ^4.0",
"symfony/options-resolver": "^3.3 || ^4.0",
"symfony/console": "^3.3 || ^4.0"
"symfony/console": "^3.3 || ^4.0",
"geocoder-php/algolia-places-provider": "^0.1.0"
},
"require-dev": {
"symfony/phpunit-bridge": "^3.4 || ^4.0",
Expand Down