more method deprecations for uniform syntax
authorgggeek <giunta.gaetano@gmail.com>
Mon, 6 Feb 2023 16:30:35 +0000 (16:30 +0000)
committergggeek <giunta.gaetano@gmail.com>
Mon, 6 Feb 2023 16:30:35 +0000 (16:30 +0000)
NEWS.md
doc/api_changes_v4.10.md
src/Client.php
src/Server.php

diff --git a/NEWS.md b/NEWS.md
index de8bc1b..e82def1 100644 (file)
--- a/NEWS.md
+++ b/NEWS.md
 
 * new: in the dispatch map, it is now possible to set different exception handling modes for each exposed xml-rpc method
 
-* new: method `Server::add_to_map` has acquired new parameters: `$parametersType = false, $exceptionHandling = false`
+* new: method `Server::add_to_map` is deprecated in favour of `addToMap`. It has also acquired new parameters:
+  `$parametersType = false, $exceptionHandling = false`
 
 * improved: the `XMLParser` accepts more options in its constructor (see phpdocs for details)
 
index 330b48f..d60ef23 100644 (file)
@@ -148,6 +148,7 @@ Deprecated methods
 | Client  | setSSLVersion         | setOption            |
 | Client  | setUseCurl            | setOption            |
 | Client  | setUserAgent          | setOption            |
+| Server  | add_to_map            | addToMap             |
 | Server  | xml_header            | Response::xml_header |
 | Value   | serializeData         | -                    |
 
index 33c5ecd..b10100f 100644 (file)
@@ -812,6 +812,7 @@ class Client
 
         if (is_array($req)) {
             // $req is an array of Requests
+            /// @todo switch to the new syntax for multicall
             return $this->multicall($req, $timeout, $method);
         } elseif (is_string($req)) {
             $n = new static::$requestClass('');
@@ -1386,20 +1387,30 @@ class Client
      * Unfortunately, there is no server error code universally used to denote the fact that multicall is unsupported,
      * so there is no way to reliably distinguish between that and a temporary failure.
      * If you are sure that server supports multicall and do not want to fallback to using many single calls, set the
-     * fourth parameter to FALSE.
+     * 2np parameter to FALSE.
      *
      * NB: trying to shoehorn extra functionality into existing syntax has resulted
      * in pretty much convoluted code...
      *
      * @param Request[] $reqs an array of Request objects
-     * @param integer $timeout deprecated - connection timeout (in seconds). See the details in the docs for the send() method
-     * @param string $method deprecated - the http protocol variant to be used. See the details in the docs for the send() method
-     * @param boolean $fallback When true, upon receiving an error during multicall, multiple single calls will be
-     *                         attempted
+     * @param bool $noFallback When true, upon receiving an error during multicall, multiple single calls will not be
+     *                         attempted.
+     *                         Deprecated alternative, was: int - "connection timeout (in seconds). See the details in the
+     *                         docs for the send() method". Please use setOption instead to set a timeout
+     * @param string $method deprecated. Was: "the http protocol variant to be used. See the details in the docs for the send() method."
+     *                       Please use the constructor to set an http protocol variant.
+     * @param boolean $fallback deprecated. Was: "w"hen true, upon receiving an error during multicall, multiple single
+     *                          calls will be attempted"
      * @return Response[]
      */
     public function multicall($reqs, $timeout = 0, $method = '', $fallback = true)
     {
+        // BC
+        if (is_bool($timeout) && $fallback === true) {
+            $fallback = !$timeout;
+            $timeout = 0;
+        }
+
         if ($method == '') {
             $method = $this->method;
         }
index f254def..a882f64 100644 (file)
@@ -365,7 +365,7 @@ class Server
 
         // Save what we received, before parsing it
         if ($this->debug > 1) {
-            $this->debugmsg("+++GOT+++\n" . $data . "\n+++END+++");
+            $this->debugMsg("+++GOT+++\n" . $data . "\n+++END+++");
         }
 
         $resp = $this->parseRequestHeaders($data, $reqCharset, $respCharset, $respEncoding);
@@ -383,7 +383,7 @@ class Server
         }
 
         if ($this->debug > 2 && static::$_xmlrpcs_occurred_errors != '') {
-            $this->debugmsg("+++PROCESSING ERRORS AND WARNINGS+++\n" .
+            $this->debugMsg("+++PROCESSING ERRORS AND WARNINGS+++\n" .
                 static::$_xmlrpcs_occurred_errors . "+++END+++");
         }
 
@@ -460,9 +460,35 @@ class Server
      *
      * @todo raise a warning if the user tries to register a 'system.' method
      */
+    public function addToMap($methodName, $function, $sig = null, $doc = false, $sigDoc = false, $parametersType = false,
+        $exceptionHandling = false)
+    {
+       return $this->addToMap($methodName, $function, $sig, $doc, $sigDoc, $parametersType, $exceptionHandling);
+    }
+
+    /**
+     * Add a method to the dispatch map.
+     *
+     * @param string $methodName the name with which the method will be made available
+     * @param callable $function the php function that will get invoked
+     * @param array[] $sig the array of valid method signatures.
+     *                     Each element is one signature: an array of strings with at least one element
+     *                     First element = type of returned value. Elements 2..N = types of parameters 1..N
+     * @param string $doc method documentation
+     * @param array[] $sigDoc the array of valid method signatures docs, following the format of $sig but with
+     *                        descriptions instead of types (one string for return type, one per param)
+     * @param string $parametersType to allow single method handlers to receive php values instead of a Request, or vice-versa
+     * @param int $exceptionHandling @see $this->exception_handling
+     * @return void
+     *
+     * @todo raise a warning if the user tries to register a 'system.' method
+     * @deprecated use addToMap instead
+     */
     public function add_to_map($methodName, $function, $sig = null, $doc = false, $sigDoc = false, $parametersType = false,
         $exceptionHandling = false)
     {
+        $this->logDeprecationUnlessCalledBy('addToMap');
+
         $this->dmap[$methodName] = array(
             'function' => $function,
             'docstring' => $doc,
@@ -547,9 +573,9 @@ class Server
 
         if ($this->debug > 1) {
             if (function_exists('getallheaders')) {
-                $this->debugmsg(''); // empty line
+                $this->debugMsg(''); // empty line
                 foreach (getallheaders() as $name => $val) {
-                    $this->debugmsg("HEADER: $name: $val");
+                    $this->debugMsg("HEADER: $name: $val");
                 }
             }
         }
@@ -571,12 +597,12 @@ class Server
                     if ($contentEncoding == 'deflate' && $degzdata = @gzuncompress($data)) {
                         $data = $degzdata;
                         if ($this->debug > 1) {
-                            $this->debugmsg("\n+++INFLATED REQUEST+++[" . strlen($data) . " chars]+++\n" . $data . "\n+++END+++");
+                            $this->debugMsg("\n+++INFLATED REQUEST+++[" . strlen($data) . " chars]+++\n" . $data . "\n+++END+++");
                         }
                     } elseif ($contentEncoding == 'gzip' && $degzdata = @gzinflate(substr($data, 10))) {
                         $data = $degzdata;
                         if ($this->debug > 1) {
-                            $this->debugmsg("+++INFLATED REQUEST+++[" . strlen($data) . " chars]+++\n" . $data . "\n+++END+++");
+                            $this->debugMsg("+++INFLATED REQUEST+++[" . strlen($data) . " chars]+++\n" . $data . "\n+++END+++");
                         }
                     } else {
                         $r = new Response(0, PhpXmlRpc::$xmlrpcerr['server_decompress_fail'],
@@ -710,7 +736,7 @@ class Server
                 )
             ) {
                 if ($this->debug > 1) {
-                    $this->debugmsg("\n+++PARSED+++\n" . var_export($_xh['params'], true) . "\n+++END+++");
+                    $this->debugMsg("\n+++PARSED+++\n" . var_export($_xh['params'], true) . "\n+++END+++");
                 }
 
                 return $this->execute($_xh['method'], $_xh['params'], $_xh['pt']);
@@ -722,7 +748,7 @@ class Server
                 }
 
                 if ($this->debug > 1) {
-                    $this->debugmsg("\n+++PARSED+++\n" . var_export($req, true) . "\n+++END+++");
+                    $this->debugMsg("\n+++PARSED+++\n" . var_export($req, true) . "\n+++END+++");
                 }
 
                 return $this->execute($req);
@@ -983,7 +1009,7 @@ class Server
      * @param string $string
      * @return void
      */
-    protected function debugmsg($string)
+    protected function debugMsg($string)
     {
         $this->debug_info .= $string . "\n";
     }