Skip to content

Commit b1ceb48

Browse files
qkdreyerdbu
authored andcommitted
fix: allow configuration of php-http/socket-client >=2.0
1 parent 56a1c37 commit b1ceb48

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/Client.php

+8-6
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ class Client implements HttpClient
3232
/**
3333
* Constructor.
3434
*
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
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} $configOrResponseFactory
36+
* @param array|null $config2 Mistake when refactoring the constructor from version 1 to version 2 - used as $config if set and $configOrResponseFactory is a response factory instance
37+
* @param array $config intended for version 1 BC, used as $config if $config2 is not set and $configOrResponseFactory is a response factory instance
3638
*
3739
* string|null remote_socket Remote entrypoint (can be a tcp or unix domain address)
3840
* int timeout Timeout before canceling request
@@ -43,17 +45,17 @@ class Client implements HttpClient
4345
* int write_buffer_size Buffer when writing the request body, defaults to 8192
4446
* int ssl_method Crypto method for ssl/tls, see PHP doc, defaults to STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT
4547
*/
46-
public function __construct($config1 = [], $config2 = null, array $config = [])
48+
public function __construct($configOrResponseFactory = [], $config2 = null, array $config = [])
4749
{
48-
if (\is_array($config1)) {
49-
$this->config = $this->configure($config1);
50+
if (\is_array($configOrResponseFactory)) {
51+
$this->config = $this->configure($configOrResponseFactory);
5052

5153
return;
5254
}
5355

54-
@trigger_error('Passing a Psr\Http\Message\ResponseFactoryInterface and a Psr\Http\Message\StreamFactoryInterface to SocketClient is deprecated, and will be removed in 3.0, you should only pass config options.', E_USER_DEPRECATED);
56+
@trigger_error('Passing a Psr\Http\Message\ResponseFactoryInterface to SocketClient is deprecated, and will be removed in 3.0, you should only pass config options.', E_USER_DEPRECATED);
5557

56-
$this->config = $this->configure($config);
58+
$this->config = $this->configure($config2 ?: $config);
5759
}
5860

5961
/**

0 commit comments

Comments
 (0)