@@ -24,29 +24,24 @@ class Client implements HttpClient
24
24
use RequestWriter;
25
25
use ResponseReader;
26
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
- ];
27
+ /**
28
+ * @var array{remote_socket: string|null, timeout: int, stream_context: resource, stream_context_options: array<string, mixed>, stream_context_param: array<string, mixed>, ssl: ?boolean, write_buffer_size: int, ssl_method: int}
29
+ */
30
+ private $ config ;
36
31
37
32
/**
38
33
* Constructor.
39
34
*
40
- * @param array $config {
35
+ * @param array{remote_socket?: string|null, timeout?: int, stream_context?: resource, stream_context_options?: array<string, mixed>, stream_context_param?: array<string, mixed>, ssl?: ?boolean, write_buffer_size?: int, ssl_method?: int} $config
41
36
*
42
- * @var string $ remote_socket Remote entrypoint (can be a tcp or unix domain address)
43
- * @var int $ timeout Timeout before canceling request
44
- * @var array $stream_context_options Context options as defined in the PHP documentation
45
- * @var array $stream_context_param Context params as defined in the PHP documentation
46
- * @var bool $ssl Use ssl, default to scheme from request, false if not present
47
- * @var int $write_buffer_size Buffer when writing the request body, defaults to 8192
48
- * @var int $ssl_method Crypto method for ssl/tls, see PHP doc , defaults to STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT
49
- * }
37
+ * string|null remote_socket Remote entrypoint (can be a tcp or unix domain address)
38
+ * int timeout Timeout before canceling request
39
+ * stream resource The initialized stream context, if not set the context is created from the options and param.
40
+ * array<string, mixed> stream_context_options Context options as defined in the PHP documentation
41
+ * array<string, mixed> stream_context_param Context params as defined in the PHP documentation
42
+ * boolean ssl Use ssl, default to scheme from request, false if not present
43
+ * int write_buffer_size Buffer when writing the request body , defaults to 8192
44
+ * int ssl_method Crypto method for ssl/tls, see PHP doc, defaults to STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT
50
45
*/
51
46
public function __construct ($ config1 = [], $ config2 = null , array $ config = [])
52
47
{
@@ -120,10 +115,10 @@ protected function createSocket(RequestInterface $request, string $remote, bool
120
115
throw new ConnectionException ($ errMsg , $ request );
121
116
}
122
117
123
- stream_set_timeout ($ socket , floor ($ this ->config ['timeout ' ] / 1000 ), $ this ->config ['timeout ' ] % 1000 );
118
+ stream_set_timeout ($ socket , ( int ) floor ($ this ->config ['timeout ' ] / 1000 ), $ this ->config ['timeout ' ] % 1000 );
124
119
125
120
if ($ useSsl && false === @stream_socket_enable_crypto ($ socket , true , $ this ->config ['ssl_method ' ])) {
126
- throw new SSLConnectionException (sprintf ('Cannot enable tls: %s ' , error_get_last ()['message ' ]), $ request );
121
+ throw new SSLConnectionException (sprintf ('Cannot enable tls: %s ' , error_get_last ()['message ' ] ?? ' no error reported ' ), $ request );
127
122
}
128
123
129
124
return $ socket ;
@@ -133,6 +128,8 @@ protected function createSocket(RequestInterface $request, string $remote, bool
133
128
* Close the socket, used when having an error.
134
129
*
135
130
* @param resource $socket
131
+ *
132
+ * @return void
136
133
*/
137
134
protected function closeSocket ($ socket )
138
135
{
@@ -142,19 +139,26 @@ protected function closeSocket($socket)
142
139
/**
143
140
* Return configuration for the socket client.
144
141
*
145
- * @param array $config Configuration from user
142
+ * @param array{remote_socket?: string|null, timeout?: int, stream_context?: resource, stream_context_options?: array<string, mixed>, stream_context_param?: array<string, mixed>, ssl?: ?boolean, write_buffer_size?: int, ssl_method?: int} $config
146
143
*
147
- * @return array Configuration resolved
144
+ * @return array{remote_socket: string|null, timeout: int, stream_context: resource, stream_context_options: array<string, mixed>, stream_context_param: array<string, mixed>, ssl: ?boolean, write_buffer_size: int, ssl_method: int}
148
145
*/
149
146
protected function configure (array $ config = [])
150
147
{
151
148
$ resolver = new OptionsResolver ();
152
- $ resolver ->setDefaults ($ this ->config );
149
+ $ resolver ->setDefaults ([
150
+ 'remote_socket ' => null ,
151
+ 'timeout ' => null ,
152
+ 'stream_context_options ' => [],
153
+ 'stream_context_param ' => [],
154
+ 'ssl ' => null ,
155
+ 'write_buffer_size ' => 8192 ,
156
+ 'ssl_method ' => STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT,
157
+ ]);
153
158
$ resolver ->setDefault ('stream_context ' , function (Options $ options ) {
154
159
return stream_context_create ($ options ['stream_context_options ' ], $ options ['stream_context_param ' ]);
155
160
});
156
-
157
- $ resolver ->setDefault ('timeout ' , ini_get ('default_socket_timeout ' ) * 1000 );
161
+ $ resolver ->setDefault ('timeout ' , ((int ) ini_get ('default_socket_timeout ' )) * 1000 );
158
162
159
163
$ resolver ->setAllowedTypes ('stream_context_options ' , 'array ' );
160
164
$ resolver ->setAllowedTypes ('stream_context_param ' , 'array ' );
0 commit comments