From c6d05f7ec297f4d680df621caa6f6106d8cf876f Mon Sep 17 00:00:00 2001 From: gggeek Date: Tue, 24 Jan 2023 15:29:18 +0000 Subject: [PATCH] add Client::getUrl --- NEWS.md | 2 ++ src/Client.php | 30 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/NEWS.md b/NEWS.md index 1014ba99..8b8e3aef 100644 --- a/NEWS.md +++ b/NEWS.md @@ -59,6 +59,8 @@ * new: added the `Client::setTimeout` method, meant to replace usage of the `$timeout` argument in calls to `send` and `multicall` +* new: method `Client::getUrl()` + * new: method `Server::setDispatchMap()` * new: it is now possible to inject a custom logger into helper classes `Charset`, `Http`, `XMLParser`, inching a step diff --git a/src/Client.php b/src/Client.php index 150f9e2f..82c32e54 100644 --- a/src/Client.php +++ b/src/Client.php @@ -37,9 +37,25 @@ class Client /// @todo: do all the ones below need to be public? + /** + * @var string + * @internal use getUrl + */ public $method = 'http'; + /** + * @var string + * @internal use getUrl + */ public $server; + /** + * @var int + * @internal use getUrl + */ public $port = 0; + /** + * @var string + * @internal use getUrl + */ public $path; /** @@ -617,6 +633,20 @@ class Client return $this; } + /** + * @return string + */ + public function getUrl() + { + $url = $this->method . '://' . $this->server; + if (($this->port = 80 && in_array($this->method, array('http', 'http10', 'http11', 'h2c'))) && + ($this->port = 443 && in_array($this->method, array('https', 'h2')))) { + return $url . $this->path; + } else { + return $url . ':' . $this->port . $this->path; + } + } + /** * Send an xml-rpc request to the server. * -- 2.47.0