Skip to content

Commit

Permalink
Expect a PSR-18 client instead of a PHP-HTTP client
Browse files Browse the repository at this point in the history
  • Loading branch information
JaZo committed Aug 15, 2022
1 parent 97e9eb8 commit 31e862e
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 16 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) princip

## [Unreleased]

### Changed

- Expect a PSR-18 client instead of a PHP-HTTP client. N.B. PHP-HTTP clients implement this interface, so it should not be a breaking change.

### Removed

- PHP <7.4 support
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@ $ composer require swisnl/geocoder-php-nationaal-georegister-provider

### HTTP Client

PHP Geocoder is decoupled from any HTTP messaging client with the help of [PHP-HTTP](http://php-http.org/).
This requires another package providing [php-http/client-implementation](https://packagist.org/providers/php-http/client-implementation).
To use Guzzle 6, for example, simply require `php-http/guzzle6-adapter`:
PHP Geocoder is decoupled from any HTTP messaging client with the help of [PSR-18 HTTP Client](https://www.php-fig.org/psr/psr-18/).
This requires another package providing [psr/http-client-implementation](https://packagist.org/providers/psr/http-client-implementation).
To use Guzzle 7, for example, simply require `guzzlehttp/guzzle`:

``` bash
$ composer require php-http/guzzle6-adapter
$ composer require guzzlehttp/guzzle
```

## Usage

``` php
// Create geocoder
$client = new \Http\Client\Curl\Client();
$client = new \GuzzleHttp\Client();
$geocoder = new \Swis\Geocoder\NationaalGeoregister\NationaalGeoregister($client);

// Geocode!
Expand Down Expand Up @@ -70,7 +70,7 @@ Example using extra options:

``` php
// On the geocoder instance:
$client = new \Http\Client\Curl\Client();
$client = new \GuzzleHttp\Client();
$options = ['fq' => 'bron:BAG'];
$geocoder = new \Swis\Geocoder\NationaalGeoregister\NationaalGeoregister($client, $options);

Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
"require": {
"php": "^7.4 || ^8.0",
"ext-json": "*",
"geocoder-php/common-http": "^4.0",
"willdurand/geocoder": "^4.0"
"geocoder-php/common-http": "^4.5",
"willdurand/geocoder": "^4.6"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.4",
"geocoder-php/provider-integration-tests": "^1.5",
"friendsofphp/php-cs-fixer": "^3.9",
"geocoder-php/provider-integration-tests": "^1.6",
"php-http/curl-client": "^2.0",
"phpunit/phpunit": "^9.0"
},
Expand Down
8 changes: 4 additions & 4 deletions src/NationaalGeoregister.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use Geocoder\Provider\Provider;
use Geocoder\Query\GeocodeQuery;
use Geocoder\Query\ReverseQuery;
use Http\Client\HttpClient;
use Psr\Http\Client\ClientInterface;

class NationaalGeoregister extends AbstractHttpProvider implements Provider
{
Expand Down Expand Up @@ -63,10 +63,10 @@ class NationaalGeoregister extends AbstractHttpProvider implements Provider
protected $options = [];

/**
* @param \Http\Client\HttpClient $client An HTTP adapter
* @param array $options Extra query parameters (optional)
* @param \Psr\Http\Client\ClientInterface $client An HTTP adapter
* @param array $options Extra query parameters (optional)
*/
public function __construct(HttpClient $client, array $options = [])
public function __construct(ClientInterface $client, array $options = [])
{
parent::__construct($client);

Expand Down
4 changes: 2 additions & 2 deletions tests/IntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Swis\Geocoder\NationaalGeoregister\Tests;

use Geocoder\IntegrationTest\ProviderIntegrationTest;
use Http\Client\HttpClient;
use Psr\Http\Client\ClientInterface;
use Swis\Geocoder\NationaalGeoregister\NationaalGeoregister;

class IntegrationTest extends ProviderIntegrationTest
Expand All @@ -20,7 +20,7 @@ class IntegrationTest extends ProviderIntegrationTest

protected $testIpv6 = false;

protected function createProvider(HttpClient $httpClient)
protected function createProvider(ClientInterface $httpClient)
{
return new NationaalGeoregister($httpClient);
}
Expand Down

0 comments on commit 31e862e

Please sign in to comment.