Skip to content

Commit b485f1d

Browse files
committed
Update to use PSR-17 and PSR-18
1 parent 9bc1e9e commit b485f1d

File tree

3 files changed

+31
-37
lines changed

3 files changed

+31
-37
lines changed

README.md

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,18 @@ the [php-sru-search](https://github.com/Zeitschriftendatenbank/php-sru-search) p
1616

1717
## Install using Composer
1818

19-
Make sure you have [Composer](https://getcomposer.org) installed, then run
19+
Use [Composer](https://getcomposer.org) to install sru-client with a compatible HTTP library such as Guzzle:
2020

2121
```bash
22-
composer require scriptotek/sru-client
22+
composer require scriptotek/sru-client php-http/guzzle6-adapter http-interop/http-factory-guzzle
2323
```
2424

25-
in your project directory to get the latest stable version of the package.
25+
We use [HTTP discovery](https://github.com/http-interop/http-factory-discovery) to discover
26+
[HTTP client](https://packagist.org/providers/psr/http-client-implementation) and
27+
[HTTP factory](https://packagist.org/providers/psr/http-factory-implementation) implementations,
28+
so Guzzle can be swapped with any other
29+
[PSR-17](https://www.php-fig.org/psr/psr-17/)/[PSR-18](https://www.php-fig.org/psr/psr-18/)-compatible library.
2630

27-
**You also need a HTTP library**. If you're not already using one in your project,
28-
just add Guzzle:
29-
30-
```bash
31-
composer require php-http/guzzle6-adapter
32-
```
33-
34-
[HTTPlug discovery](http://php-http.readthedocs.io/en/latest/discovery.html) is
35-
used in order to not depend on a specific library.
3631

3732
## Configuring the client
3833

composer.json

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,17 @@
77
"require": {
88
"php" : "^7.1",
99
"danmichaelo/quitesimplexmlelement": "^1.0",
10-
"php-http/client-implementation": "^1.0",
11-
"php-http/httplug": "^1.1",
12-
"php-http/message-factory": "^1.0",
13-
"php-http/discovery": "^1.0",
14-
"php-http/client-common": "^1.5"
10+
"psr/http-client-implementation": "^1.0",
11+
"psr/http-factory-implementation": "^1.0",
12+
"http-interop/http-factory-discovery": "^1.4",
13+
"php-http/client-common": "^2.0"
1514
},
1615
"require-dev": {
1716
"phpunit/phpunit": "^7.0 || ^8.0",
1817
"sami/sami": "^3.3",
1918
"php-http/mock-client": "^1.0",
20-
"php-http/message": "^1.0",
21-
"guzzlehttp/psr7": "^1.0",
22-
"php-http/guzzle6-adapter": "^1.1"
19+
"http-interop/http-factory-guzzle": "^1.0",
20+
"php-http/guzzle6-adapter": "^2.0"
2321
},
2422
"license": "MIT",
2523
"authors": [

src/Client.php

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,25 @@
22

33
use Http\Client\Common\Plugin\AuthenticationPlugin;
44
use Http\Client\Common\PluginClient;
5-
use Http\Client\HttpClient;
6-
use Http\Discovery\HttpClientDiscovery;
75
use Http\Client\Common\Exception\ServerErrorException;
8-
use Http\Client\Common\Plugin\ErrorPlugin;
9-
use Http\Discovery\MessageFactoryDiscovery;
6+
use Http\Factory\Discovery\HttpClient;
7+
use Http\Factory\Discovery\HttpFactory;
108
use Http\Message\Authentication\BasicAuth;
11-
use Http\Message\MessageFactory;
9+
use Psr\Http\Client\ClientInterface;
10+
use Psr\Http\Message\RequestFactoryInterface;
1211

1312
/**
1413
* SRU client
1514
*/
1615
class Client
1716
{
18-
/** @var HttpClient */
17+
/** @var ClientInterface */
1918
protected $httpClient;
2019

21-
/** @var MessageFactory */
22-
protected $messageFactory;
20+
/**
21+
* @var RequestFactoryInterface
22+
*/
23+
private $requestFactory;
2324

2425
/** @var string SRU service base URL */
2526
protected $url;
@@ -52,17 +53,17 @@ class Client
5253
/**
5354
* Create a new client
5455
*
55-
* @param string $url Base URL to the SRU service
56-
* @param array $options Associative array of options
57-
* @param HttpClient $httpClient
58-
* @param MessageFactory|null $messageFactory
56+
* @param string $url Base URL to the SRU service
57+
* @param array $options Associative array of options
58+
* @param ClientInterface $httpClient
59+
* @param RequestFactoryInterface $requestFactory
5960
* @throws \ErrorException
6061
*/
6162
public function __construct(
6263
$url,
6364
$options = null,
64-
HttpClient $httpClient = null,
65-
MessageFactory $messageFactory = null
65+
ClientInterface $httpClient = null,
66+
RequestFactoryInterface $requestFactory = null
6667
) {
6768
$this->url = $url;
6869
$options = $options ?: array();
@@ -95,8 +96,8 @@ public function __construct(
9596
throw new\ErrorException('Not supported');
9697
}
9798

98-
$this->httpClient = new PluginClient($httpClient ?: HttpClientDiscovery::find(), $plugins);
99-
$this->messageFactory = $messageFactory ?: MessageFactoryDiscovery::find();
99+
$this->httpClient = new PluginClient($httpClient ?: HttpClient::client(), $plugins);
100+
$this->requestFactory = $requestFactory ?: HttpFactory::requestFactory();
100101
}
101102

102103
/**
@@ -212,7 +213,7 @@ public function explain()
212213
*/
213214
public function request($method, $url)
214215
{
215-
$request = $this->messageFactory->createRequest($method, $url, $this->headers);
216+
$request = $this->requestFactory->createRequest($method, $url, $this->headers);
216217
$response = $this->httpClient->sendRequest($request);
217218

218219
if ($response->getStatusCode() >= 500 && $response->getStatusCode() < 600) {

0 commit comments

Comments
 (0)