|
2 | 2 |
|
3 | 3 | use Http\Client\Common\Plugin\AuthenticationPlugin;
|
4 | 4 | use Http\Client\Common\PluginClient;
|
5 |
| -use Http\Client\HttpClient; |
6 |
| -use Http\Discovery\HttpClientDiscovery; |
7 | 5 | 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; |
10 | 8 | use Http\Message\Authentication\BasicAuth;
|
11 |
| -use Http\Message\MessageFactory; |
| 9 | +use Psr\Http\Client\ClientInterface; |
| 10 | +use Psr\Http\Message\RequestFactoryInterface; |
12 | 11 |
|
13 | 12 | /**
|
14 | 13 | * SRU client
|
15 | 14 | */
|
16 | 15 | class Client
|
17 | 16 | {
|
18 |
| - /** @var HttpClient */ |
| 17 | + /** @var ClientInterface */ |
19 | 18 | protected $httpClient;
|
20 | 19 |
|
21 |
| - /** @var MessageFactory */ |
22 |
| - protected $messageFactory; |
| 20 | + /** |
| 21 | + * @var RequestFactoryInterface |
| 22 | + */ |
| 23 | + private $requestFactory; |
23 | 24 |
|
24 | 25 | /** @var string SRU service base URL */
|
25 | 26 | protected $url;
|
@@ -52,17 +53,17 @@ class Client
|
52 | 53 | /**
|
53 | 54 | * Create a new client
|
54 | 55 | *
|
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 |
59 | 60 | * @throws \ErrorException
|
60 | 61 | */
|
61 | 62 | public function __construct(
|
62 | 63 | $url,
|
63 | 64 | $options = null,
|
64 |
| - HttpClient $httpClient = null, |
65 |
| - MessageFactory $messageFactory = null |
| 65 | + ClientInterface $httpClient = null, |
| 66 | + RequestFactoryInterface $requestFactory = null |
66 | 67 | ) {
|
67 | 68 | $this->url = $url;
|
68 | 69 | $options = $options ?: array();
|
@@ -95,8 +96,8 @@ public function __construct(
|
95 | 96 | throw new\ErrorException('Not supported');
|
96 | 97 | }
|
97 | 98 |
|
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(); |
100 | 101 | }
|
101 | 102 |
|
102 | 103 | /**
|
@@ -212,7 +213,7 @@ public function explain()
|
212 | 213 | */
|
213 | 214 | public function request($method, $url)
|
214 | 215 | {
|
215 |
| - $request = $this->messageFactory->createRequest($method, $url, $this->headers); |
| 216 | + $request = $this->requestFactory->createRequest($method, $url, $this->headers); |
216 | 217 | $response = $this->httpClient->sendRequest($request);
|
217 | 218 |
|
218 | 219 | if ($response->getStatusCode() >= 500 && $response->getStatusCode() < 600) {
|
|
0 commit comments