1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Http\Client\Plugin; |
4
|
|
|
|
5
|
1 |
|
@trigger_error('The '.__NAMESPACE__.'\PluginClient class is deprecated since version 1.1 and will be removed in 2.0. Use Http\Client\Common\PluginClient instead.', E_USER_DEPRECATED); |
|
|
|
|
6
|
|
|
|
7
|
|
|
use Http\Client\HttpAsyncClient; |
8
|
|
|
use Http\Client\HttpClient; |
9
|
|
|
use Http\Client\Plugin\Exception\LoopException; |
10
|
|
|
use Psr\Http\Message\RequestInterface; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* The client managing plugins and providing a decorator around HTTP Clients. |
14
|
|
|
* |
15
|
|
|
* @author Joel Wurtz <[email protected]> |
16
|
|
|
* |
17
|
|
|
* @deprecated since since version 1.1, and will be removed in 2.0. Use {@link \Http\Client\Common\PluginClient} instead. |
18
|
|
|
*/ |
19
|
|
|
final class PluginClient implements HttpClient, HttpAsyncClient |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @var \Http\Client\Common\PluginClient |
23
|
|
|
*/ |
24
|
|
|
private $pluginClient; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @param HttpClient|HttpAsyncClient $client |
28
|
|
|
* @param Plugin[] $plugins |
29
|
|
|
* @param array $options { |
30
|
|
|
* |
31
|
|
|
* @var int $max_restarts Number of times plugins may initiate a restart of the plugin chain. Defaults to 10. |
32
|
|
|
* } |
33
|
|
|
* |
34
|
|
|
* @throws \RuntimeException if client is not an instance of HttpClient or HttpAsyncClient |
35
|
|
|
*/ |
36
|
8 |
|
public function __construct($client, array $plugins = [], array $options = []) |
37
|
|
|
{ |
38
|
8 |
|
$this->pluginClient = new \Http\Client\Common\PluginClient($client, $plugins, $options); |
39
|
8 |
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* {@inheritdoc} |
43
|
|
|
*/ |
44
|
4 |
View Code Duplication |
public function sendRequest(RequestInterface $request) |
45
|
|
|
{ |
46
|
|
|
try { |
47
|
4 |
|
return $this->pluginClient->sendRequest($request); |
48
|
1 |
|
} catch (\Http\Client\Common\Exception\LoopException $e) { |
49
|
1 |
|
throw new LoopException($e->getMessage(), $e->getRequest(), $e); |
|
|
|
|
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* {@inheritdoc} |
55
|
|
|
*/ |
56
|
1 |
View Code Duplication |
public function sendAsyncRequest(RequestInterface $request) |
57
|
1 |
|
{ |
58
|
|
|
try { |
59
|
1 |
|
return $this->pluginClient->sendAsyncRequest($request); |
60
|
|
|
} catch (\Http\Client\Common\Exception\LoopException $e) { |
61
|
|
|
throw new LoopException($e->getMessage(), $e->getRequest(), $e); |
|
|
|
|
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
If you suppress an error, we recommend checking for the error condition explicitly: