From b9175a856dcac971760d4ee74221c7a5c7a6e4b8 Mon Sep 17 00:00:00 2001 From: gggeek Date: Wed, 8 Feb 2023 16:03:30 +0000 Subject: [PATCH] add one more Client option --- NEWS.md | 4 ++++ src/Client.php | 11 +++++++++++ tests/09HTTPTest.php | 7 +++++++ 3 files changed, 22 insertions(+) diff --git a/NEWS.md b/NEWS.md index 6a8f7078..5214c3f2 100644 --- a/NEWS.md +++ b/NEWS.md @@ -92,6 +92,10 @@ * new: added methods `getOption`, `setOption`, `setOptions` and `getOptions` to both Client and Server, meant to replace direct access to _all public properties_ as well as the `$timeout` argument in calls to `Client::send` and `Client::multicall` +* new: by using `Client::setOption('extracurlopts')`, it is possible to pass in protocol=specific options for when + using the Socket http transport. The value has to be an array with key being 'socket' or 'ssl', and the value an array + (see https://www.php.net/manual/en/context.socket.php and https://www.php.net/manual/en/context.ssl.php) + * new: it is now possible to inject a custom logger into helper classes `Charset`, `Http`, `XMLParser`, inching a step closer to supporting DIC patterns (issue #78) diff --git a/src/Client.php b/src/Client.php index f45c6a2e..3a6662b1 100644 --- a/src/Client.php +++ b/src/Client.php @@ -36,6 +36,7 @@ class Client const OPT_COOKIES = 'cookies'; const OPT_DEBUG = 'debug'; const OPT_EXTRA_CURL_OPTS = 'extracurlopts'; + const OPT_EXTRA_SOCKET_OPTS = 'extrasockopts'; const OPT_KEEPALIVE = 'keepalive'; const OPT_KEY = 'key'; const OPT_KEY_PASS = 'keypass'; @@ -168,6 +169,10 @@ class Client * @var array */ protected $cookies = array(); + /** + * @var array + */ + protected $extrasockopts = array(); /** * @var array */ @@ -1032,6 +1037,12 @@ class Client $contextOptions['ssl']['verify_peer_name'] = $opts['verifypeer']; } + foreach ($opts['extracurlopts'] as $proto => $protoOpts) { + foreach ($protoOpts as $key => $val) { + $contextOptions[$proto][$key] = $val; + } + } + $context = stream_context_create($contextOptions); if ($opts['timeout'] <= 0) { diff --git a/tests/09HTTPTest.php b/tests/09HTTPTest.php index ed4348ea..ffff037f 100644 --- a/tests/09HTTPTest.php +++ b/tests/09HTTPTest.php @@ -332,6 +332,13 @@ class HTTPTest extends ServerTest $this->client->setSSLVersion($this->args['SSLVERSION']); $this->client->setUseCurl(\PhpXmlRpc\Client::USE_CURL_NEVER); + if (version_compare(PHP_VERSION, '8.0', '>')) + { + $version = explode('.', PHP_VERSION); + $this->client->setOption(\PhpXmlRpc\Client::OPT_EXTRA_SOCKET_OPTS, + array('ssl' => array('security_level' => 2 + $version[1]))); + } + $this->$method(); } -- 2.47.0