Skip to content
Merged
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
46 changes: 20 additions & 26 deletions doc/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ bazinga_geocoder:
acme:
factory: Bazinga\GeocoderBundle\ProviderFactory\GoogleMapsFactory
options:
httplug_client: '@httplug.client' # When using HTTPlugBundle
http_client: '@any.psr18.client'
region: 'Sweden'
api_key: 'xxyy'
```
Expand All @@ -116,7 +116,7 @@ bazinga_geocoder:
factory: Bazinga\GeocoderBundle\ProviderFactory\TomTomFactory
options:
api_key: 'xxyy'
httplug_client: '@httplug.client' # When using HTTPlugBundle
http_client: '@any.psr18.client'
region: 'Sweden'
chain:
factory: Bazinga\GeocoderBundle\ProviderFactory\ChainFactory
Expand Down Expand Up @@ -295,17 +295,27 @@ your service argument as: `!tagged bazinga_geocoder.dumper`.

### Custom HTTP Clients

The HTTP geocoder providers integrates with [HTTPlug](http://httplug.io/). It will give you all
the power of the HTTP client. You have to select which one you want to use and how
you want to configure it.
The HTTP geocoder allows to use any [PSR-18](https://www.php-fig.org/psr/psr-18/) compatible client.
In Symfony apps it is recommended to use `symfony/http-client`, but if you want to use Guzzle,
just require it in your dependencies:

Read their [usage page](http://docs.php-http.org/en/latest/httplug/users.html), you
may also be interested in checking out the [HTTPlugBundle](https://github.com/php-http/HttplugBundle).
```bash
composer require guzzlehttp/guzzle http-interop/http-factory-guzzle
```

An example, if you want to use Guzzle6.
And configure your provider to use it:

```bash
composer require php-http/guzzle6-adapter php-http/message
```yaml
services:
guzzle.client:
class: GuzzleHttp\Client

bazinga_geocoder:
providers:
acme:
factory: ...
options:
http_client: '@guzzle.client'
```

Reference Configuration
Expand Down Expand Up @@ -372,19 +382,3 @@ Setup the test suite using [Composer](http://getcomposer.org/):
composer update
composer test
```

### Doctrine test

There is also a test that tests the doctrine integration. It runs automatically on
[GitHub Actions](https://github.com/geocoder-php/BazingaGeocoderBundle/actions) but if you want to run it locally you must do the following.

```bash
composer require phpunit/phpunit:^9.5 --no-update
composer update --prefer-source
wget https://phar.phpunit.de/phpunit-9.5.phar
php phpunit-9.5.phar --testsuit doctrine
```

**Important:** this command must be run with `--prefer-source`, otherwise the
`Doctrine\Tests\OrmTestCase` class won't be found.

50 changes: 25 additions & 25 deletions doc/services.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,35 @@ Here is a list of all provider factories and their options.

| Service | Options |
| ------- | ------- |
| `Bazinga\GeocoderBundle\ProviderFactory\AlgoliaPlaceFactory` | httplug_client, api_key, app_id
| `Bazinga\GeocoderBundle\ProviderFactory\ArcGISOnlineFactory` | httplug_client, source_country
| `Bazinga\GeocoderBundle\ProviderFactory\BingMapsFactory` | httplug_client, api_key
| `Bazinga\GeocoderBundle\ProviderFactory\AlgoliaPlaceFactory` | http_client, api_key, app_id
| `Bazinga\GeocoderBundle\ProviderFactory\ArcGISOnlineFactory` | http_client, source_country
| `Bazinga\GeocoderBundle\ProviderFactory\BingMapsFactory` | http_client, api_key
| `Bazinga\GeocoderBundle\ProviderFactory\ChainFactory` | services
| `Bazinga\GeocoderBundle\ProviderFactory\FreeGeoIpFactory` | httplug_client, base_url
| `Bazinga\GeocoderBundle\ProviderFactory\FreeGeoIpFactory` | http_client, base_url
| `Bazinga\GeocoderBundle\ProviderFactory\GeoIP2Factory` | provider, database_filename, user_id, license_key, webservice_options, locales, provider_service
| `Bazinga\GeocoderBundle\ProviderFactory\GeoipFactory` |
| `Bazinga\GeocoderBundle\ProviderFactory\GeoIPsFactory` | httplug_client, api_key
| `Bazinga\GeocoderBundle\ProviderFactory\GeonamesFactory` | httplug_client, username
| `Bazinga\GeocoderBundle\ProviderFactory\GeoPluginFactory` | httplug_client
| `Bazinga\GeocoderBundle\ProviderFactory\GoogleMapsFactory` | httplug_client, api_key, region
| `Bazinga\GeocoderBundle\ProviderFactory\GoogleMapsPlacesFactory` | httplug_client, api_key
| `Bazinga\GeocoderBundle\ProviderFactory\HereFactory` | httplug_client, app_id, app_code, use_cit
| `Bazinga\GeocoderBundle\ProviderFactory\HostIpFactory` | httplug_client
| `Bazinga\GeocoderBundle\ProviderFactory\IpInfoFactory` | httplug_client
| `Bazinga\GeocoderBundle\ProviderFactory\IpInfoDbFactory` | httplug_client, api_key, precision
| `Bazinga\GeocoderBundle\ProviderFactory\IpstackFactory` | httplug_client, api_key
| `Bazinga\GeocoderBundle\ProviderFactory\LocationIQFactory` | httplug_client, api_key
| `Bazinga\GeocoderBundle\ProviderFactory\MapboxFactory` | httplug_client, api_key, country, mode
| `Bazinga\GeocoderBundle\ProviderFactory\MapQuestFactory` | httplug_client, api_key, licensed
| `Bazinga\GeocoderBundle\ProviderFactory\MapzenFactory` | httplug_client, api_key
| `Bazinga\GeocoderBundle\ProviderFactory\GeoIPsFactory` | http_client, api_key
| `Bazinga\GeocoderBundle\ProviderFactory\GeonamesFactory` | http_client, username
| `Bazinga\GeocoderBundle\ProviderFactory\GeoPluginFactory` | http_client
| `Bazinga\GeocoderBundle\ProviderFactory\GoogleMapsFactory` | http_client, api_key, region
| `Bazinga\GeocoderBundle\ProviderFactory\GoogleMapsPlacesFactory` | http_client, api_key
| `Bazinga\GeocoderBundle\ProviderFactory\HereFactory` | http_client, app_id, app_code, use_cit
| `Bazinga\GeocoderBundle\ProviderFactory\HostIpFactory` | http_client
| `Bazinga\GeocoderBundle\ProviderFactory\IpInfoFactory` | http_client
| `Bazinga\GeocoderBundle\ProviderFactory\IpInfoDbFactory` | http_client, api_key, precision
| `Bazinga\GeocoderBundle\ProviderFactory\IpstackFactory` | http_client, api_key
| `Bazinga\GeocoderBundle\ProviderFactory\LocationIQFactory` | http_client, api_key
| `Bazinga\GeocoderBundle\ProviderFactory\MapboxFactory` | http_client, api_key, country, mode
| `Bazinga\GeocoderBundle\ProviderFactory\MapQuestFactory` | http_client, api_key, licensed
| `Bazinga\GeocoderBundle\ProviderFactory\MapzenFactory` | http_client, api_key
| `Bazinga\GeocoderBundle\ProviderFactory\MaxMindBinaryFactory` | dat_file, open_flag
| `Bazinga\GeocoderBundle\ProviderFactory\MaxMindFactory` | httplug_client, api_key, endpoint
| `Bazinga\GeocoderBundle\ProviderFactory\NominatimFactory` | httplug_client, root_url
| `Bazinga\GeocoderBundle\ProviderFactory\OpenCageFactory` | httplug_client, api_key
| `Bazinga\GeocoderBundle\ProviderFactory\OpenRouteServiceFactory` | httplug_client, api_key
| `Bazinga\GeocoderBundle\ProviderFactory\PickPointFactory` | httplug_client, api_key
| `Bazinga\GeocoderBundle\ProviderFactory\TomTomFactory` | httplug_client, api_key
| `Bazinga\GeocoderBundle\ProviderFactory\YandexFactory` | httplug_client, toponym
| `Bazinga\GeocoderBundle\ProviderFactory\MaxMindFactory` | http_client, api_key, endpoint
| `Bazinga\GeocoderBundle\ProviderFactory\NominatimFactory` | http_client, root_url
| `Bazinga\GeocoderBundle\ProviderFactory\OpenCageFactory` | http_client, api_key
| `Bazinga\GeocoderBundle\ProviderFactory\OpenRouteServiceFactory` | http_client, api_key
| `Bazinga\GeocoderBundle\ProviderFactory\PickPointFactory` | http_client, api_key
| `Bazinga\GeocoderBundle\ProviderFactory\TomTomFactory` | http_client, api_key
| `Bazinga\GeocoderBundle\ProviderFactory\YandexFactory` | http_client, toponym

### Services

Expand Down
8 changes: 2 additions & 6 deletions src/ProviderFactory/AlgoliaFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,25 @@ final class AlgoliaFactory extends AbstractFactory
];

/**
* @param array{api_key: ?string, app_id: ?string, http_client: ?ClientInterface, httplug_client: ?ClientInterface} $config
* @param array{api_key: ?string, app_id: ?string, http_client: ?ClientInterface} $config
*/
protected function getProvider(array $config): Provider
{
$httpClient = $config['http_client'] ?? $config['httplug_client'] ?? $this->httpClient ?? Psr18ClientDiscovery::find();
$httpClient = $config['http_client'] ?? $this->httpClient ?? Psr18ClientDiscovery::find();

return new AlgoliaPlaces($httpClient, $config['api_key'], $config['app_id']);
}

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

$resolver->setAllowedTypes('httplug_client', ['object', 'null']);
$resolver->setAllowedTypes('http_client', ['object', 'null']);
$resolver->setAllowedTypes('api_key', ['string', 'null']);
$resolver->setAllowedTypes('app_id', ['string', 'null']);

$resolver->setDeprecated('httplug_client', 'willdurand/geocoder-bundle', '5.19', 'The option "httplug_client" is deprecated, use "http_client" instead.');
}
}
8 changes: 2 additions & 6 deletions src/ProviderFactory/ArcGISOnlineFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,23 @@ final class ArcGISOnlineFactory extends AbstractFactory
];

/**
* @param array{source_country: ?string, http_client: ?ClientInterface, httplug_client: ?ClientInterface} $config
* @param array{source_country: ?string, http_client: ?ClientInterface} $config
*/
protected function getProvider(array $config): Provider
{
$httpClient = $config['http_client'] ?? $config['httplug_client'] ?? $this->httpClient ?? Psr18ClientDiscovery::find();
$httpClient = $config['http_client'] ?? $this->httpClient ?? Psr18ClientDiscovery::find();

return new ArcGISOnline($httpClient, $config['source_country']);
}

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

$resolver->setAllowedTypes('httplug_client', ['object', 'null']);
$resolver->setAllowedTypes('http_client', ['object', 'null']);
$resolver->setAllowedTypes('source_country', ['string', 'null']);

$resolver->setDeprecated('httplug_client', 'willdurand/geocoder-bundle', '5.19', 'The option "httplug_client" is deprecated, use "http_client" instead.');
}
}
8 changes: 2 additions & 6 deletions src/ProviderFactory/BingMapsFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,23 @@ final class BingMapsFactory extends AbstractFactory
];

/**
* @param array{api_key: string, http_client: ?ClientInterface, httplug_client: ?ClientInterface} $config
* @param array{api_key: string, http_client: ?ClientInterface} $config
*/
protected function getProvider(array $config): Provider
{
$httpClient = $config['http_client'] ?? $config['httplug_client'] ?? $this->httpClient ?? Psr18ClientDiscovery::find();
$httpClient = $config['http_client'] ?? $this->httpClient ?? Psr18ClientDiscovery::find();

return new BingMaps($httpClient, $config['api_key']);
}

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

$resolver->setRequired('api_key');
$resolver->setAllowedTypes('httplug_client', ['object', 'null']);
$resolver->setAllowedTypes('http_client', ['object', 'null']);
$resolver->setAllowedTypes('api_key', ['string']);

$resolver->setDeprecated('httplug_client', 'willdurand/geocoder-bundle', '5.19', 'The option "httplug_client" is deprecated, use "http_client" instead.');
}
}
8 changes: 2 additions & 6 deletions src/ProviderFactory/FreeGeoIpFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,23 @@ final class FreeGeoIpFactory extends AbstractFactory
];

/**
* @param array{base_url: string, http_client: ?ClientInterface, httplug_client: ?ClientInterface} $config
* @param array{base_url: string, http_client: ?ClientInterface} $config
*/
protected function getProvider(array $config): Provider
{
$httpClient = $config['http_client'] ?? $config['httplug_client'] ?? $this->httpClient ?? Psr18ClientDiscovery::find();
$httpClient = $config['http_client'] ?? $this->httpClient ?? Psr18ClientDiscovery::find();

return new FreeGeoIp($httpClient, $config['base_url']);
}

protected static function configureOptionResolver(OptionsResolver $resolver)
{
$resolver->setDefaults([
'httplug_client' => null,
'http_client' => null,
'base_url' => 'https://freegeoip.app/json/%s',
]);

$resolver->setAllowedTypes('httplug_client', ['object', 'null']);
$resolver->setAllowedTypes('http_client', ['object', 'null']);
$resolver->setAllowedTypes('base_url', ['string']);

$resolver->setDeprecated('httplug_client', 'willdurand/geocoder-bundle', '5.19', 'The option "httplug_client" is deprecated, use "http_client" instead.');
}
}
8 changes: 2 additions & 6 deletions src/ProviderFactory/GeoPluginFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,21 @@ final class GeoPluginFactory extends AbstractFactory
];

/**
* @param array{http_client: ?ClientInterface, httplug_client: ?ClientInterface} $config
* @param array{http_client: ?ClientInterface} $config
*/
protected function getProvider(array $config): Provider
{
$httpClient = $config['http_client'] ?? $config['httplug_client'] ?? $this->httpClient ?? Psr18ClientDiscovery::find();
$httpClient = $config['http_client'] ?? $this->httpClient ?? Psr18ClientDiscovery::find();

return new GeoPlugin($httpClient);
}

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

$resolver->setAllowedTypes('httplug_client', ['object', 'null']);
$resolver->setAllowedTypes('http_client', ['object', 'null']);

$resolver->setDeprecated('httplug_client', 'willdurand/geocoder-bundle', '5.19', 'The option "httplug_client" is deprecated, use "http_client" instead.');
}
}
8 changes: 2 additions & 6 deletions src/ProviderFactory/GeonamesFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,23 @@ final class GeonamesFactory extends AbstractFactory
];

/**
* @param array{username: string, http_client: ?ClientInterface, httplug_client: ?ClientInterface} $config
* @param array{username: string, http_client: ?ClientInterface} $config
*/
protected function getProvider(array $config): Provider
{
$httpClient = $config['http_client'] ?? $config['httplug_client'] ?? $this->httpClient ?? Psr18ClientDiscovery::find();
$httpClient = $config['http_client'] ?? $this->httpClient ?? Psr18ClientDiscovery::find();

return new Geonames($httpClient, $config['username']);
}

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

$resolver->setRequired('username');
$resolver->setAllowedTypes('httplug_client', ['object', 'null']);
$resolver->setAllowedTypes('http_client', ['object', 'null']);
$resolver->setAllowedTypes('username', ['string']);

$resolver->setDeprecated('httplug_client', 'willdurand/geocoder-bundle', '5.19', 'The option "httplug_client" is deprecated, use "http_client" instead.');
}
}
8 changes: 2 additions & 6 deletions src/ProviderFactory/GoogleMapsFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,25 @@ final class GoogleMapsFactory extends AbstractFactory
];

/**
* @param array{api_key: ?string, region: ?string, http_client: ?ClientInterface, httplug_client: ?ClientInterface} $config
* @param array{api_key: ?string, region: ?string, http_client: ?ClientInterface} $config
*/
protected function getProvider(array $config): Provider
{
$httpClient = $config['httplug_client'] ?? $this->httpClient ?? Psr18ClientDiscovery::find();
$httpClient = $config['http_client'] ?? $this->httpClient ?? Psr18ClientDiscovery::find();

return new GoogleMaps($httpClient, $config['region'], $config['api_key']);
}

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

$resolver->setAllowedTypes('httplug_client', ['object', 'null']);
$resolver->setAllowedTypes('http_client', ['object', 'null']);
$resolver->setAllowedTypes('region', ['string', 'null']);
$resolver->setAllowedTypes('api_key', ['string', 'null']);

$resolver->setDeprecated('httplug_client', 'willdurand/geocoder-bundle', '5.19', 'The option "%name%" is deprecated, use "http_client" instead.');
}
}
8 changes: 2 additions & 6 deletions src/ProviderFactory/GoogleMapsPlacesFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,23 @@ final class GoogleMapsPlacesFactory extends AbstractFactory
];

/**
* @param array{api_key: string, http_client: ?ClientInterface, httplug_client: ?ClientInterface} $config
* @param array{api_key: string, http_client: ?ClientInterface} $config
*/
protected function getProvider(array $config): Provider
{
$httpClient = $config['http_client'] ?? $config['httplug_client'] ?? $this->httpClient ?? Psr18ClientDiscovery::find();
$httpClient = $config['http_client'] ?? $this->httpClient ?? Psr18ClientDiscovery::find();

return new GoogleMapsPlaces($httpClient, $config['api_key']);
}

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

$resolver->setAllowedTypes('httplug_client', ['object', 'null']);
$resolver->setAllowedTypes('http_client', ['object', 'null']);
$resolver->setRequired(['api_key']);
$resolver->setAllowedTypes('api_key', ['string']);

$resolver->setDeprecated('httplug_client', 'willdurand/geocoder-bundle', '5.19', 'The option "httplug_client" is deprecated, use "http_client" instead.');
}
}
Loading
Loading