Skip to content

Commit a79f50a

Browse files
authored
Merge pull request #274 from nicolas-grekas/inject-http-client
Allow an HTTP client to be injected via the constructor of providers
2 parents 494f0b6 + 26e7d33 commit a79f50a

26 files changed

+33
-23
lines changed

ProviderFactory/AbstractFactory.php

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

1515
use Geocoder\Provider\Provider;
16+
use Http\Client\HttpClient;
1617
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
1718
use Symfony\Component\OptionsResolver\OptionsResolver;
1819

@@ -26,6 +27,13 @@ abstract class AbstractFactory implements ProviderFactoryInterface
2627
{
2728
protected static $dependencies = [];
2829

30+
protected $httpClient;
31+
32+
public function __construct(HttpClient $httpClient = null)
33+
{
34+
$this->httpClient = $httpClient;
35+
}
36+
2937
abstract protected function getProvider(array $config): Provider;
3038

3139
/**

ProviderFactory/AlgoliaFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ final class AlgoliaFactory extends AbstractFactory
2525

2626
protected function getProvider(array $config): Provider
2727
{
28-
$httplug = $config['httplug_client'] ?: HttpClientDiscovery::find();
28+
$httplug = $config['httplug_client'] ?: $this->httpClient ?? HttpClientDiscovery::find();
2929

3030
return new AlgoliaPlaces($httplug, $config['api_key'], $config['app_id']);
3131
}

ProviderFactory/ArcGISOnlineFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ final class ArcGISOnlineFactory extends AbstractFactory
2525

2626
protected function getProvider(array $config): Provider
2727
{
28-
$httplug = $config['httplug_client'] ?: HttpClientDiscovery::find();
28+
$httplug = $config['httplug_client'] ?: $this->httpClient ?? HttpClientDiscovery::find();
2929

3030
return new ArcGISOnline($httplug, $config['source_country']);
3131
}

ProviderFactory/BingMapsFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ final class BingMapsFactory extends AbstractFactory
2525

2626
protected function getProvider(array $config): Provider
2727
{
28-
$httplug = $config['httplug_client'] ?: HttpClientDiscovery::find();
28+
$httplug = $config['httplug_client'] ?: $this->httpClient ?? HttpClientDiscovery::find();
2929

3030
return new BingMaps($httplug, $config['api_key']);
3131
}

ProviderFactory/FreeGeoIpFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ final class FreeGeoIpFactory extends AbstractFactory
2525

2626
protected function getProvider(array $config): Provider
2727
{
28-
$httplug = $config['httplug_client'] ?: HttpClientDiscovery::find();
28+
$httplug = $config['httplug_client'] ?: $this->httpClient ?? HttpClientDiscovery::find();
2929

3030
return new FreeGeoIp($httplug, $config['base_url']);
3131
}

ProviderFactory/GeoIPsFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ protected function getProvider(array $config): Provider
3030
{
3131
@trigger_error('Bazinga\GeocoderBundle\ProviderFactory\GeoIPsFactory is deprecated since 5.6, to be removed in 6.0. See https://github.com/geocoder-php/Geocoder/issues/965', E_USER_DEPRECATED);
3232

33-
$httplug = $config['httplug_client'] ?: HttpClientDiscovery::find();
33+
$httplug = $config['httplug_client'] ?: $this->httpClient ?? HttpClientDiscovery::find();
3434

3535
return new GeoIPs($httplug, $config['api_key']);
3636
}

ProviderFactory/GeoPluginFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ final class GeoPluginFactory extends AbstractFactory
2525

2626
protected function getProvider(array $config): Provider
2727
{
28-
$httplug = $config['httplug_client'] ?: HttpClientDiscovery::find();
28+
$httplug = $config['httplug_client'] ?: $this->httpClient ?? HttpClientDiscovery::find();
2929

3030
return new GeoPlugin($httplug);
3131
}

ProviderFactory/GeonamesFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ final class GeonamesFactory extends AbstractFactory
2525

2626
protected function getProvider(array $config): Provider
2727
{
28-
$httplug = $config['httplug_client'] ?: HttpClientDiscovery::find();
28+
$httplug = $config['httplug_client'] ?: $this->httpClient ?? HttpClientDiscovery::find();
2929

3030
return new Geonames($httplug, $config['username']);
3131
}

ProviderFactory/GoogleMapsFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ final class GoogleMapsFactory extends AbstractFactory
2525

2626
protected function getProvider(array $config): Provider
2727
{
28-
$httplug = $config['httplug_client'] ?: HttpClientDiscovery::find();
28+
$httplug = $config['httplug_client'] ?: $this->httpClient ?? HttpClientDiscovery::find();
2929

3030
return new GoogleMaps($httplug, $config['region'], $config['api_key']);
3131
}

ProviderFactory/GoogleMapsPlacesFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ final class GoogleMapsPlacesFactory extends AbstractFactory
2525

2626
protected function getProvider(array $config): Provider
2727
{
28-
$httplug = $config['httplug_client'] ?: HttpClientDiscovery::find();
28+
$httplug = $config['httplug_client'] ?: $this->httpClient ?? HttpClientDiscovery::find();
2929

3030
return new GoogleMapsPlaces($httplug, $config['api_key']);
3131
}

0 commit comments

Comments
 (0)