1 | <?php |
||
22 | class Client implements HttpClient |
||
23 | { |
||
24 | use RequestWriter; |
||
25 | use ResponseReader; |
||
26 | |||
27 | private $config = [ |
||
28 | 'remote_socket' => null, |
||
29 | 'timeout' => null, |
||
30 | 'stream_context_options' => [], |
||
31 | 'stream_context_param' => [], |
||
32 | 'ssl' => null, |
||
33 | 'write_buffer_size' => 8192, |
||
34 | 'ssl_method' => STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT, |
||
35 | ]; |
||
36 | |||
37 | private $hasAsync; |
||
38 | |||
39 | /** |
||
40 | * Constructor. |
||
41 | * |
||
42 | * @param array $config { |
||
43 | * |
||
44 | * @var string $remote_socket Remote entrypoint (can be a tcp or unix domain address) |
||
45 | * @var int $timeout Timeout before canceling request |
||
46 | * @var array $stream_context_options Context options as defined in the PHP documentation |
||
47 | * @var array $stream_context_param Context params as defined in the PHP documentation |
||
48 | * @var bool $ssl Use ssl, default to scheme from request, false if not present |
||
49 | * @var int $write_buffer_size Buffer when writing the request body, defaults to 8192 |
||
50 | * @var int $ssl_method Crypto method for ssl/tls, see PHP doc, defaults to STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT |
||
51 | * } |
||
52 | */ |
||
53 | 64 | public function __construct($config1 = [], $config2 = null, array $config = []) |
|
67 | |||
68 | /** |
||
69 | * {@inheritdoc} |
||
70 | */ |
||
71 | 64 | public function sendRequest(RequestInterface $request): ResponseInterface |
|
101 | |||
102 | /** |
||
103 | * Create the socket to write request and read response on it. |
||
104 | * |
||
105 | * @param RequestInterface $request Request for |
||
106 | * @param string $remote Entrypoint for the connection |
||
107 | * @param bool $useSsl Whether to use ssl or not |
||
108 | * |
||
109 | * @throws ConnectionException|SSLConnectionException When the connection fail |
||
110 | * |
||
111 | * @return resource Socket resource |
||
112 | */ |
||
113 | 63 | protected function createSocket(RequestInterface $request, string $remote, bool $useSsl) |
|
135 | |||
136 | /** |
||
137 | * Close the socket, used when having an error. |
||
138 | * |
||
139 | * @param resource $socket |
||
140 | */ |
||
141 | 1 | protected function closeSocket($socket) |
|
145 | |||
146 | /** |
||
147 | * Return configuration for the socket client. |
||
148 | * |
||
149 | * @param array $config Configuration from user |
||
150 | * |
||
151 | * @return array Configuration resolved |
||
152 | */ |
||
153 | 64 | protected function configure(array $config = []) |
|
170 | |||
171 | /** |
||
172 | * Return remote socket from the request. |
||
173 | * |
||
174 | * |
||
175 | * @throws InvalidRequestException When no remote can be determined from the request |
||
176 | * |
||
177 | * @return string |
||
178 | */ |
||
179 | 55 | private function determineRemoteFromRequest(RequestInterface $request) |
|
200 | } |
||
201 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.