vendor/willdurand/geocoder-bundle/src/ProviderFactory/GoogleMapsFactory.php line 30

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  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. namespace Bazinga\GeocoderBundle\ProviderFactory;
  11. use Geocoder\Provider\GoogleMaps\GoogleMaps;
  12. use Geocoder\Provider\Provider;
  13. use Http\Discovery\HttpClientDiscovery;
  14. use Psr\Http\Client\ClientInterface;
  15. use Symfony\Component\OptionsResolver\OptionsResolver;
  16. final class GoogleMapsFactory extends AbstractFactory
  17. {
  18.     protected static $dependencies = [
  19.         ['requiredClass' => GoogleMaps::class, 'packageName' => 'geocoder-php/google-maps-provider'],
  20.     ];
  21.     /**
  22.      * @param array{api_key: ?string, region: ?string, http_client: ?ClientInterface, httplug_client: ?ClientInterface} $config
  23.      */
  24.     protected function getProvider(array $config): Provider
  25.     {
  26.         $httpClient $config['httplug_client'] ?? $this->httpClient ?? HttpClientDiscovery::find();
  27.         return new GoogleMaps($httpClient$config['region'], $config['api_key']);
  28.     }
  29.     protected static function configureOptionResolver(OptionsResolver $resolver)
  30.     {
  31.         $resolver->setDefaults([
  32.             'httplug_client' => null,
  33.             'http_client' => null,
  34.             'region' => null,
  35.             'api_key' => null,
  36.         ]);
  37.         $resolver->setAllowedTypes('httplug_client', ['object''null']);
  38.         $resolver->setAllowedTypes('http_client', ['object''null']);
  39.         $resolver->setAllowedTypes('region', ['string''null']);
  40.         $resolver->setAllowedTypes('api_key', ['string''null']);
  41.         $resolver->setDeprecated('httplug_client''willdurand/geocoder-bundle''5.19''The option "%name%" is deprecated, use "http_client" instead.');
  42.     }
  43. }