add Client::getUrl
authorgggeek <giunta.gaetano@gmail.com>
Tue, 24 Jan 2023 15:29:18 +0000 (15:29 +0000)
committergggeek <giunta.gaetano@gmail.com>
Tue, 24 Jan 2023 15:29:18 +0000 (15:29 +0000)
NEWS.md
src/Client.php

diff --git a/NEWS.md b/NEWS.md
index 1014ba9..8b8e3ae 100644 (file)
--- 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
index 150f9e2..82c32e5 100644 (file)
@@ -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.
      *