Skip to content

Commit fb87655

Browse files
authored
Merge pull request #331 from norkunas/psr-client
Allow PSR-18 client
2 parents d0b509e + ce46499 commit fb87655

37 files changed

+282
-184
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
The changelog describes what have been "Added", "Changed", "Removed" or "Fixed" between versions.
44

5+
## Version 5.19.0
6+
7+
### Changed
8+
9+
- Allow PSR-18 client
10+
- Updated Geocoder Provider dependency requirements to the latest versions
11+
512
## Version 5.18.0
613

714
### Added

ProviderFactory/AbstractFactory.php

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

1515
use Geocoder\Provider\Provider;
16-
use Http\Client\HttpClient;
16+
use Psr\Http\Client\ClientInterface;
1717
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
1818
use Symfony\Component\OptionsResolver\OptionsResolver;
1919

@@ -30,18 +30,15 @@ abstract class AbstractFactory implements ProviderFactoryInterface
3030
*/
3131
protected static $dependencies = [];
3232

33-
/**
34-
* @var HttpClient|null
35-
*/
36-
protected $httpClient;
33+
protected ?ClientInterface $httpClient;
3734

38-
public function __construct(HttpClient $httpClient = null)
35+
public function __construct(?ClientInterface $httpClient = null)
3936
{
4037
$this->httpClient = $httpClient;
4138
}
4239

4340
/**
44-
* @phpstan-param array<mixed, mixed> $config
41+
* @param array<mixed, mixed> $config
4542
*/
4643
abstract protected function getProvider(array $config): Provider;
4744

ProviderFactory/AlgoliaFactory.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515
use Geocoder\Provider\AlgoliaPlaces\AlgoliaPlaces;
1616
use Geocoder\Provider\Provider;
17-
use Http\Client\HttpClient;
1817
use Http\Discovery\HttpClientDiscovery;
18+
use Psr\Http\Client\ClientInterface;
1919
use Symfony\Component\OptionsResolver\OptionsResolver;
2020

2121
final class AlgoliaFactory extends AbstractFactory
@@ -25,7 +25,7 @@ final class AlgoliaFactory extends AbstractFactory
2525
];
2626

2727
/**
28-
* @phpstan-param array{api_key: ?string, app_id: ?string, httplug_client: ?HttpClient} $config
28+
* @param array{api_key: ?string, app_id: ?string, httplug_client: ?ClientInterface} $config
2929
*/
3030
protected function getProvider(array $config): Provider
3131
{
@@ -42,7 +42,7 @@ protected static function configureOptionResolver(OptionsResolver $resolver)
4242
'app_id' => null,
4343
]);
4444

45-
$resolver->setAllowedTypes('httplug_client', ['object', 'null']);
45+
$resolver->setAllowedTypes('httplug_client', [ClientInterface::class, 'null']);
4646
$resolver->setAllowedTypes('api_key', ['string', 'null']);
4747
$resolver->setAllowedTypes('app_id', ['string', 'null']);
4848
}

ProviderFactory/ArcGISOnlineFactory.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515
use Geocoder\Provider\ArcGISOnline\ArcGISOnline;
1616
use Geocoder\Provider\Provider;
17-
use Http\Client\HttpClient;
1817
use Http\Discovery\HttpClientDiscovery;
18+
use Psr\Http\Client\ClientInterface;
1919
use Symfony\Component\OptionsResolver\OptionsResolver;
2020

2121
final class ArcGISOnlineFactory extends AbstractFactory
@@ -25,7 +25,7 @@ final class ArcGISOnlineFactory extends AbstractFactory
2525
];
2626

2727
/**
28-
* @phpstan-param array{source_country: ?string, httplug_client: ?HttpClient} $config
28+
* @param array{source_country: ?string, httplug_client: ?ClientInterface} $config
2929
*/
3030
protected function getProvider(array $config): Provider
3131
{
@@ -41,7 +41,7 @@ protected static function configureOptionResolver(OptionsResolver $resolver)
4141
'source_country' => null,
4242
]);
4343

44-
$resolver->setAllowedTypes('httplug_client', ['object', 'null']);
44+
$resolver->setAllowedTypes('httplug_client', [ClientInterface::class, 'null']);
4545
$resolver->setAllowedTypes('source_country', ['string', 'null']);
4646
}
4747
}

ProviderFactory/BingMapsFactory.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515
use Geocoder\Provider\BingMaps\BingMaps;
1616
use Geocoder\Provider\Provider;
17-
use Http\Client\HttpClient;
1817
use Http\Discovery\HttpClientDiscovery;
18+
use Psr\Http\Client\ClientInterface;
1919
use Symfony\Component\OptionsResolver\OptionsResolver;
2020

2121
final class BingMapsFactory extends AbstractFactory
@@ -25,7 +25,7 @@ final class BingMapsFactory extends AbstractFactory
2525
];
2626

2727
/**
28-
* @phpstan-param array{api_key: string, httplug_client: ?HttpClient} $config
28+
* @param array{api_key: string, httplug_client: ?ClientInterface} $config
2929
*/
3030
protected function getProvider(array $config): Provider
3131
{
@@ -41,7 +41,7 @@ protected static function configureOptionResolver(OptionsResolver $resolver)
4141
]);
4242

4343
$resolver->setRequired('api_key');
44-
$resolver->setAllowedTypes('httplug_client', ['object', 'null']);
44+
$resolver->setAllowedTypes('httplug_client', [ClientInterface::class, 'null']);
4545
$resolver->setAllowedTypes('api_key', ['string']);
4646
}
4747
}

ProviderFactory/ChainFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ final class ChainFactory extends AbstractFactory implements LoggerAwareInterface
3030
];
3131

3232
/**
33-
* @phpstan-param array{services: Provider[]} $config
33+
* @param array{services: Provider[]} $config
3434
*/
3535
protected function getProvider(array $config): Provider
3636
{

ProviderFactory/FreeGeoIpFactory.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515
use Geocoder\Provider\FreeGeoIp\FreeGeoIp;
1616
use Geocoder\Provider\Provider;
17-
use Http\Client\HttpClient;
1817
use Http\Discovery\HttpClientDiscovery;
18+
use Psr\Http\Client\ClientInterface;
1919
use Symfony\Component\OptionsResolver\OptionsResolver;
2020

2121
final class FreeGeoIpFactory extends AbstractFactory
@@ -25,7 +25,7 @@ final class FreeGeoIpFactory extends AbstractFactory
2525
];
2626

2727
/**
28-
* @phpstan-param array{base_url: string, httplug_client: ?HttpClient} $config
28+
* @param array{base_url: string, httplug_client: ?ClientInterface} $config
2929
*/
3030
protected function getProvider(array $config): Provider
3131
{
@@ -41,7 +41,7 @@ protected static function configureOptionResolver(OptionsResolver $resolver)
4141
'base_url' => 'https://freegeoip.app/json/%s',
4242
]);
4343

44-
$resolver->setAllowedTypes('httplug_client', ['object', 'null']);
44+
$resolver->setAllowedTypes('httplug_client', [ClientInterface::class, 'null']);
4545
$resolver->setAllowedTypes('base_url', ['string']);
4646
}
4747
}

ProviderFactory/GeoIP2Factory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ final class GeoIP2Factory extends AbstractFactory
2727
];
2828

2929
/**
30-
* @phpstan-param array{provider: string, provider_service: ?ProviderInterface, model: string, user_id: string|int|null, license_key: string|null, locales: list<string>, webservice_options: array<mixed, mixed>, database_filename: ?string} $config
30+
* @param array{provider: string, provider_service: ?ProviderInterface, model: string, user_id: string|int|null, license_key: string|null, locales: list<string>, webservice_options: array<mixed, mixed>, database_filename: ?string} $config
3131
*/
3232
protected function getProvider(array $config): Provider
3333
{
@@ -61,7 +61,7 @@ protected static function configureOptionResolver(OptionsResolver $resolver)
6161

6262
$resolver->setRequired('provider');
6363
$resolver->setAllowedTypes('provider', ['string']);
64-
$resolver->setAllowedTypes('provider_service', ['object', 'null']);
64+
$resolver->setAllowedTypes('provider_service', [ProviderInterface::class, 'null']);
6565
$resolver->setAllowedTypes('model', ['string']);
6666
$resolver->setAllowedTypes('user_id', ['string', 'int', 'null']);
6767
$resolver->setAllowedTypes('license_key', ['string', 'null']);

ProviderFactory/GeoIPsFactory.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,14 @@ final class GeoIPsFactory extends AbstractFactory
2828
];
2929

3030
/**
31-
* @phpstan-param array{api_key: string, httplug_client: ?HttpClient} $config
31+
* @param array{api_key: string, httplug_client: ?HttpClient} $config
3232
*/
3333
protected function getProvider(array $config): Provider
3434
{
3535
@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);
3636

3737
$httplug = $config['httplug_client'] ?: $this->httpClient ?? HttpClientDiscovery::find();
38+
assert($httplug instanceof HttpClient);
3839

3940
return new GeoIPs($httplug, $config['api_key']);
4041
}
@@ -46,7 +47,7 @@ protected static function configureOptionResolver(OptionsResolver $resolver)
4647
]);
4748

4849
$resolver->setRequired('api_key');
49-
$resolver->setAllowedTypes('httplug_client', ['object', 'null']);
50+
$resolver->setAllowedTypes('httplug_client', [HttpClient::class, 'null']);
5051
$resolver->setAllowedTypes('api_key', ['string']);
5152
}
5253
}

ProviderFactory/GeoPluginFactory.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515
use Geocoder\Provider\GeoPlugin\GeoPlugin;
1616
use Geocoder\Provider\Provider;
17-
use Http\Client\HttpClient;
1817
use Http\Discovery\HttpClientDiscovery;
18+
use Psr\Http\Client\ClientInterface;
1919
use Symfony\Component\OptionsResolver\OptionsResolver;
2020

2121
final class GeoPluginFactory extends AbstractFactory
@@ -25,7 +25,7 @@ final class GeoPluginFactory extends AbstractFactory
2525
];
2626

2727
/**
28-
* @phpstan-param array{httplug_client: ?HttpClient} $config
28+
* @param array{httplug_client: ?ClientInterface} $config
2929
*/
3030
protected function getProvider(array $config): Provider
3131
{
@@ -40,6 +40,6 @@ protected static function configureOptionResolver(OptionsResolver $resolver)
4040
'httplug_client' => null,
4141
]);
4242

43-
$resolver->setAllowedTypes('httplug_client', ['object', 'null']);
43+
$resolver->setAllowedTypes('httplug_client', [ClientInterface::class, 'null']);
4444
}
4545
}

ProviderFactory/GeoipFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ final class GeoipFactory extends AbstractFactory
2323
];
2424

2525
/**
26-
* @phpstan-param array{} $config
26+
* @param array{} $config
2727
*/
2828
protected function getProvider(array $config): Provider
2929
{

ProviderFactory/GeonamesFactory.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515
use Geocoder\Provider\Geonames\Geonames;
1616
use Geocoder\Provider\Provider;
17-
use Http\Client\HttpClient;
1817
use Http\Discovery\HttpClientDiscovery;
18+
use Psr\Http\Client\ClientInterface;
1919
use Symfony\Component\OptionsResolver\OptionsResolver;
2020

2121
final class GeonamesFactory extends AbstractFactory
@@ -25,7 +25,7 @@ final class GeonamesFactory extends AbstractFactory
2525
];
2626

2727
/**
28-
* @phpstan-param array{username: string, httplug_client: ?HttpClient} $config
28+
* @param array{username: string, httplug_client: ?ClientInterface} $config
2929
*/
3030
protected function getProvider(array $config): Provider
3131
{
@@ -41,7 +41,7 @@ protected static function configureOptionResolver(OptionsResolver $resolver)
4141
]);
4242

4343
$resolver->setRequired('username');
44-
$resolver->setAllowedTypes('httplug_client', ['object', 'null']);
44+
$resolver->setAllowedTypes('httplug_client', [ClientInterface::class, 'null']);
4545
$resolver->setAllowedTypes('username', ['string']);
4646
}
4747
}

ProviderFactory/GoogleMapsFactory.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515
use Geocoder\Provider\GoogleMaps\GoogleMaps;
1616
use Geocoder\Provider\Provider;
17-
use Http\Client\HttpClient;
1817
use Http\Discovery\HttpClientDiscovery;
18+
use Psr\Http\Client\ClientInterface;
1919
use Symfony\Component\OptionsResolver\OptionsResolver;
2020

2121
final class GoogleMapsFactory extends AbstractFactory
@@ -25,7 +25,7 @@ final class GoogleMapsFactory extends AbstractFactory
2525
];
2626

2727
/**
28-
* @phpstan-param array{api_key: ?string, region: ?string, httplug_client: ?HttpClient} $config
28+
* @param array{api_key: ?string, region: ?string, httplug_client: ?ClientInterface} $config
2929
*/
3030
protected function getProvider(array $config): Provider
3131
{
@@ -42,7 +42,7 @@ protected static function configureOptionResolver(OptionsResolver $resolver)
4242
'api_key' => null,
4343
]);
4444

45-
$resolver->setAllowedTypes('httplug_client', ['object', 'null']);
45+
$resolver->setAllowedTypes('httplug_client', [ClientInterface::class, 'null']);
4646
$resolver->setAllowedTypes('region', ['string', 'null']);
4747
$resolver->setAllowedTypes('api_key', ['string', 'null']);
4848
}

ProviderFactory/GoogleMapsPlacesFactory.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515
use Geocoder\Provider\GoogleMapsPlaces\GoogleMapsPlaces;
1616
use Geocoder\Provider\Provider;
17-
use Http\Client\HttpClient;
1817
use Http\Discovery\HttpClientDiscovery;
18+
use Psr\Http\Client\ClientInterface;
1919
use Symfony\Component\OptionsResolver\OptionsResolver;
2020

2121
final class GoogleMapsPlacesFactory extends AbstractFactory
@@ -25,7 +25,7 @@ final class GoogleMapsPlacesFactory extends AbstractFactory
2525
];
2626

2727
/**
28-
* @phpstan-param array{api_key: string, httplug_client: ?HttpClient} $config
28+
* @param array{api_key: string, httplug_client: ?ClientInterface} $config
2929
*/
3030
protected function getProvider(array $config): Provider
3131
{
@@ -40,7 +40,7 @@ protected static function configureOptionResolver(OptionsResolver $resolver)
4040
'httplug_client' => null,
4141
]);
4242

43-
$resolver->setAllowedTypes('httplug_client', ['object', 'null']);
43+
$resolver->setAllowedTypes('httplug_client', [ClientInterface::class, 'null']);
4444
$resolver->setRequired(['api_key']);
4545
$resolver->setAllowedTypes('api_key', ['string']);
4646
}

ProviderFactory/HereFactory.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515
use Geocoder\Provider\Here\Here;
1616
use Geocoder\Provider\Provider;
17-
use Http\Client\HttpClient;
1817
use Http\Discovery\HttpClientDiscovery;
18+
use Psr\Http\Client\ClientInterface;
1919
use Symfony\Component\OptionsResolver\OptionsResolver;
2020

2121
final class HereFactory extends AbstractFactory
@@ -25,7 +25,7 @@ final class HereFactory extends AbstractFactory
2525
];
2626

2727
/**
28-
* @phpstan-param array{app_key: ?string, app_id: ?string, app_code: ?string, use_cit: bool, httplug_client: ?HttpClient} $config
28+
* @param array{app_key: ?string, app_id: ?string, app_code: ?string, use_cit: bool, httplug_client: ?ClientInterface} $config
2929
*/
3030
protected function getProvider(array $config): Provider
3131
{
@@ -56,7 +56,7 @@ protected static function configureOptionResolver(OptionsResolver $resolver)
5656
'app_code' => null,
5757
]);
5858

59-
$resolver->setAllowedTypes('httplug_client', ['object', 'null']);
59+
$resolver->setAllowedTypes('httplug_client', [ClientInterface::class, 'null']);
6060
$resolver->setAllowedTypes('app_key', ['string', 'null']);
6161
$resolver->setAllowedTypes('app_id', ['string', 'null']);
6262
$resolver->setAllowedTypes('app_code', ['string', 'null']);

ProviderFactory/HostIpFactory.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515
use Geocoder\Provider\HostIp\HostIp;
1616
use Geocoder\Provider\Provider;
17-
use Http\Client\HttpClient;
1817
use Http\Discovery\HttpClientDiscovery;
18+
use Psr\Http\Client\ClientInterface;
1919
use Symfony\Component\OptionsResolver\OptionsResolver;
2020

2121
final class HostIpFactory extends AbstractFactory
@@ -25,7 +25,7 @@ final class HostIpFactory extends AbstractFactory
2525
];
2626

2727
/**
28-
* @phpstan-param array{httplug_client: ?HttpClient} $config
28+
* @param array{httplug_client: ?ClientInterface} $config
2929
*/
3030
protected function getProvider(array $config): Provider
3131
{
@@ -40,6 +40,6 @@ protected static function configureOptionResolver(OptionsResolver $resolver)
4040
'httplug_client' => null,
4141
]);
4242

43-
$resolver->setAllowedTypes('httplug_client', ['object', 'null']);
43+
$resolver->setAllowedTypes('httplug_client', [ClientInterface::class, 'null']);
4444
}
4545
}

0 commit comments

Comments
 (0)