1 | <?php |
||
19 | final class PluginClient implements HttpClient, HttpAsyncClient |
||
20 | { |
||
21 | /** |
||
22 | * An HTTP async client. |
||
23 | * |
||
24 | * @var HttpAsyncClient |
||
25 | */ |
||
26 | private $client; |
||
27 | |||
28 | /** |
||
29 | * The plugin chain. |
||
30 | * |
||
31 | * @var Plugin[] |
||
32 | */ |
||
33 | private $plugins; |
||
34 | |||
35 | /** |
||
36 | * A list of options. |
||
37 | * |
||
38 | * @var array |
||
39 | */ |
||
40 | private $options; |
||
41 | |||
42 | /** |
||
43 | * @param HttpClient|HttpAsyncClient $client |
||
44 | * @param Plugin[] $plugins |
||
45 | * @param array $options { |
||
46 | * |
||
47 | * @var int $max_restarts |
||
48 | * @var Plugin[] $debug_plugins an array of plugins that are injected between each normal plugin |
||
49 | * } |
||
50 | * |
||
51 | * @throws \RuntimeException if client is not an instance of HttpClient or HttpAsyncClient |
||
52 | */ |
||
53 | 9 | public function __construct($client, array $plugins = [], array $options = []) |
|
66 | |||
67 | /** |
||
68 | * {@inheritdoc} |
||
69 | */ |
||
70 | 5 | public function sendRequest(RequestInterface $request) |
|
89 | |||
90 | /** |
||
91 | * {@inheritdoc} |
||
92 | */ |
||
93 | 2 | public function sendAsyncRequest(RequestInterface $request) |
|
101 | |||
102 | /** |
||
103 | * Configure the plugin client. |
||
104 | * |
||
105 | * @param array $options |
||
106 | * |
||
107 | * @return array |
||
108 | */ |
||
109 | 9 | private function configure(array $options = []) |
|
110 | { |
||
111 | 9 | $resolver = new OptionsResolver(); |
|
112 | 9 | $resolver->setDefaults([ |
|
113 | 9 | 'max_restarts' => 10, |
|
114 | 9 | 'debug_plugins' => [], |
|
115 | 9 | ]); |
|
116 | |||
117 | $resolver |
||
118 | 9 | ->setAllowedTypes('debug_plugins', 'array') |
|
119 | ->setAllowedValues('debug_plugins', function (array $plugins) { |
||
120 | 9 | foreach ($plugins as $plugin) { |
|
121 | // Make sure each object passed with the `debug_plugins` is an instance of Plugin. |
||
122 | 1 | if (!$plugin instanceof Plugin) { |
|
123 | return false; |
||
124 | } |
||
125 | 9 | } |
|
126 | |||
127 | 9 | return true; |
|
128 | 9 | }); |
|
129 | |||
130 | 9 | return $resolver->resolve($options); |
|
131 | } |
||
132 | |||
133 | /** |
||
134 | * Create the plugin chain. |
||
135 | * |
||
136 | * @param Plugin[] $pluginList A list of plugins |
||
137 | * @param callable $clientCallable Callable making the HTTP call |
||
138 | * |
||
139 | * @return callable |
||
140 | */ |
||
141 | 6 | private function createPluginChain($pluginList, callable $clientCallable) |
|
175 | } |
||
176 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: