1 | <?php |
||
19 | class Client implements HttpClient |
||
20 | { |
||
21 | use RequestWriter; |
||
22 | use ResponseReader; |
||
23 | |||
24 | private $config = [ |
||
25 | 'remote_socket' => null, |
||
26 | 'timeout' => null, |
||
27 | 'stream_context_options' => array(), |
||
28 | 'stream_context_param' => array(), |
||
29 | 'ssl' => null, |
||
30 | 'write_buffer_size' => 8192, |
||
31 | 'ssl_method' => STREAM_CRYPTO_METHOD_TLS_CLIENT |
||
32 | ]; |
||
33 | |||
34 | /** |
||
35 | * @param MessageFactory $messageFactory |
||
36 | * @param array $config |
||
37 | */ |
||
38 | 64 | public function __construct(MessageFactory $messageFactory, array $config = []) |
|
43 | |||
44 | /** |
||
45 | * {@inheritdoc} |
||
46 | */ |
||
47 | 64 | public function sendRequest(RequestInterface $request) |
|
74 | |||
75 | /** |
||
76 | * Create the socket to write request and read response on it |
||
77 | * |
||
78 | * @param RequestInterface $request Request for |
||
79 | * @param string $remote Entrypoint for the connection |
||
80 | * @param boolean $useSsl Whether to use ssl or not |
||
81 | * |
||
82 | * @throws NetworkException |
||
83 | * |
||
84 | * @return resource |
||
85 | */ |
||
86 | 63 | protected function createSocket(RequestInterface $request, $remote, $useSsl) |
|
106 | |||
107 | /** |
||
108 | * Close the socket, used when having an error |
||
109 | * |
||
110 | * @param resource $socket |
||
111 | */ |
||
112 | 1 | protected function closeSocket($socket) |
|
116 | |||
117 | /** |
||
118 | * Return configuration for the socket client |
||
119 | * |
||
120 | * @param array $config Configuration from user |
||
121 | * |
||
122 | * @return array Configuration resolved |
||
123 | */ |
||
124 | 64 | protected function configure(array $config = []) |
|
141 | |||
142 | /** |
||
143 | * Return remote socket from the request |
||
144 | * |
||
145 | * @param RequestInterface $request |
||
146 | * |
||
147 | * @throws NetworkException When no remote can be determined from the request |
||
148 | * |
||
149 | * @return string |
||
150 | */ |
||
151 | 58 | private function determineRemoteFromRequest(RequestInterface $request) |
|
168 | } |
||
169 |