1 | <?php |
||
20 | class Client implements HttpClient |
||
21 | { |
||
22 | use RequestWriter; |
||
23 | use ResponseReader; |
||
24 | |||
25 | private $config = [ |
||
26 | 'remote_socket' => null, |
||
27 | 'timeout' => null, |
||
28 | 'stream_context_options' => [], |
||
29 | 'stream_context_param' => [], |
||
30 | 'ssl' => null, |
||
31 | 'write_buffer_size' => 8192, |
||
32 | 'ssl_method' => STREAM_CRYPTO_METHOD_TLS_CLIENT, |
||
33 | ]; |
||
34 | |||
35 | /** |
||
36 | * Constructor. |
||
37 | * |
||
38 | * @param ResponseFactory $responseFactory Response factory for creating response |
||
39 | * @param array $config { |
||
40 | * |
||
41 | * @var string $remote_socket Remote entrypoint (can be a tcp or unix domain address) |
||
42 | * @var int $timeout Timeout before canceling request |
||
43 | * @var array $stream_context_options Context options as defined in the PHP documentation |
||
44 | * @var array $stream_context_param Context params as defined in the PHP documentation |
||
45 | * @var bool $ssl Use ssl, default to scheme from request, false if not present |
||
46 | * @var int $write_buffer_size Buffer when writing the request body, defaults to 8192 |
||
47 | * @var int $ssl_method Crypto method for ssl/tls, see PHP doc, defaults to STREAM_CRYPTO_METHOD_TLS_CLIENT |
||
48 | * } |
||
49 | */ |
||
50 | 64 | public function __construct(ResponseFactory $responseFactory = null, array $config = []) |
|
59 | |||
60 | /** |
||
61 | * {@inheritdoc} |
||
62 | */ |
||
63 | 64 | public function sendRequest(RequestInterface $request) |
|
97 | |||
98 | /** |
||
99 | * Create the socket to write request and read response on it. |
||
100 | * |
||
101 | * @param RequestInterface $request Request for |
||
102 | * @param string $remote Entrypoint for the connection |
||
103 | * @param bool $useSsl Whether to use ssl or not |
||
104 | * |
||
105 | * @throws NetworkException When the connection fail |
||
106 | * |
||
107 | * @return resource Socket resource |
||
108 | */ |
||
109 | 63 | protected function createSocket(RequestInterface $request, $remote, $useSsl) |
|
129 | |||
130 | /** |
||
131 | * Close the socket, used when having an error. |
||
132 | * |
||
133 | * @param resource $socket |
||
134 | */ |
||
135 | 1 | protected function closeSocket($socket) |
|
139 | |||
140 | /** |
||
141 | * Return configuration for the socket client. |
||
142 | * |
||
143 | * @param array $config Configuration from user |
||
144 | * |
||
145 | * @return array Configuration resolved |
||
146 | */ |
||
147 | 64 | protected function configure(array $config = []) |
|
164 | |||
165 | /** |
||
166 | * Return remote socket from the request. |
||
167 | * |
||
168 | * @param RequestInterface $request |
||
169 | * |
||
170 | * @throws NetworkException When no remote can be determined from the request |
||
171 | * |
||
172 | * @return string |
||
173 | */ |
||
174 | 58 | private function determineRemoteFromRequest(RequestInterface $request) |
|
191 | } |
||
192 |