|
| 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 | +} |
0 commit comments