1 | <?php |
||
21 | class Client implements HttpClient |
||
22 | { |
||
23 | use RequestWriter; |
||
24 | use ResponseReader; |
||
25 | |||
26 | private $config = [ |
||
27 | 'remote_socket' => null, |
||
28 | 'timeout' => null, |
||
29 | 'stream_context_options' => array(), |
||
30 | 'stream_context_param' => array(), |
||
31 | 'ssl' => null, |
||
32 | 'write_buffer_size' => 8192, |
||
33 | 'ssl_method' => STREAM_CRYPTO_METHOD_TLS_CLIENT |
||
34 | ]; |
||
35 | |||
36 | /** |
||
37 | * Constructor. |
||
38 | * |
||
39 | * @param ResponseFactory $responseFactory Response factory for creating response |
||
40 | * @param array $config { |
||
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 | * @throws \LogicException When MessageFactory is not provided and cannot be discovered |
||
51 | */ |
||
52 | 64 | public function __construct(ResponseFactory $responseFactory = null, array $config = []) |
|
65 | |||
66 | /** |
||
67 | * {@inheritdoc} |
||
68 | */ |
||
69 | 64 | public function sendRequest(RequestInterface $request) |
|
99 | |||
100 | /** |
||
101 | * Create the socket to write request and read response on it |
||
102 | * |
||
103 | * @param RequestInterface $request Request for |
||
104 | * @param string $remote Entrypoint for the connection |
||
105 | * @param boolean $useSsl Whether to use ssl or not |
||
106 | * |
||
107 | * @throws NetworkException When the connection fail |
||
108 | * |
||
109 | * @return resource Socket resource |
||
110 | */ |
||
111 | 63 | protected function createSocket(RequestInterface $request, $remote, $useSsl) |
|
131 | |||
132 | /** |
||
133 | * Close the socket, used when having an error |
||
134 | * |
||
135 | * @param resource $socket |
||
136 | */ |
||
137 | 1 | protected function closeSocket($socket) |
|
141 | |||
142 | /** |
||
143 | * Return configuration for the socket client |
||
144 | * |
||
145 | * @param array $config Configuration from user |
||
146 | * |
||
147 | * @return array Configuration resolved |
||
148 | */ |
||
149 | 64 | protected function configure(array $config = []) |
|
166 | |||
167 | /** |
||
168 | * Return remote socket from the request |
||
169 | * |
||
170 | * @param RequestInterface $request |
||
171 | * |
||
172 | * @throws NetworkException When no remote can be determined from the request |
||
173 | * |
||
174 | * @return string |
||
175 | */ |
||
176 | 58 | private function determineRemoteFromRequest(RequestInterface $request) |
|
193 | } |
||
194 |