1 | <?php |
||
19 | class Client implements HttpClient |
||
20 | { |
||
21 | use RequestWriter; |
||
22 | use ResponseReader; |
||
23 | |||
24 | /** |
||
25 | * Config of this client. |
||
26 | * |
||
27 | * @var array |
||
28 | */ |
||
29 | private $config = [ |
||
30 | 'remote_socket' => null, |
||
31 | 'timeout' => null, |
||
32 | 'stream_context_options' => [], |
||
33 | 'stream_context_param' => [], |
||
34 | 'ssl' => null, |
||
35 | 'write_buffer_size' => 8192, |
||
36 | 'ssl_method' => STREAM_CRYPTO_METHOD_TLS_CLIENT, |
||
37 | ]; |
||
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_TLS_CLIENT |
||
51 | * } |
||
52 | * |
||
53 | * @param array $deprecatedConfig Use for BC with old versions |
||
54 | */ |
||
55 | 64 | public function __construct($config = [], array $deprecatedConfig = []) |
|
68 | |||
69 | /** |
||
70 | * {@inheritdoc} |
||
71 | */ |
||
72 | 64 | public function sendRequest(RequestInterface $request) |
|
102 | |||
103 | /** |
||
104 | * Create the socket to write request and read response on it. |
||
105 | * |
||
106 | * @param RequestInterface $request Request for |
||
107 | * @param string $remote Entrypoint for the connection |
||
108 | * @param bool $useSsl Whether to use ssl or not |
||
109 | * |
||
110 | * @throws NetworkException When the connection fail |
||
111 | * |
||
112 | * @return resource Socket resource |
||
113 | */ |
||
114 | 63 | protected function createSocket(RequestInterface $request, $remote, $useSsl) |
|
134 | |||
135 | /** |
||
136 | * Close the socket, used when having an error. |
||
137 | * |
||
138 | * @param resource $socket |
||
139 | */ |
||
140 | 1 | protected function closeSocket($socket) |
|
144 | |||
145 | /** |
||
146 | * Return configuration for the socket client. |
||
147 | * |
||
148 | * @param array $config Configuration from user |
||
149 | * |
||
150 | * @return array Configuration resolved |
||
151 | */ |
||
152 | 64 | protected function configure(array $config = []) |
|
169 | |||
170 | /** |
||
171 | * Return remote socket from the request. |
||
172 | * |
||
173 | * @param RequestInterface $request |
||
174 | * |
||
175 | * @throws NetworkException When no remote can be determined from the request |
||
176 | * |
||
177 | * @return string |
||
178 | */ |
||
179 | 58 | private function determineRemoteFromRequest(RequestInterface $request) |
|
196 | } |
||
197 |