add more deprecation warnings on use of internal-only methods
authorgggeek <giunta.gaetano@gmail.com>
Wed, 1 Feb 2023 11:45:13 +0000 (11:45 +0000)
committergggeek <giunta.gaetano@gmail.com>
Wed, 1 Feb 2023 11:45:13 +0000 (11:45 +0000)
NEWS.md
src/Client.php
src/Traits/DeprecationLogger.php
src/Value.php

diff --git a/NEWS.md b/NEWS.md
index 84b04d4..2c45e04 100644 (file)
--- a/NEWS.md
+++ b/NEWS.md
     objects for the cases in which it previously returned a string
   - if you replaced the Logger class, take care that you will have to implement methods `error`, `warning` and `debug`
     (all is ok if you subclassed it)
+  - calling method `Value::serializeData` is now deprecated
   - traits have been introduced for all classes dealing with Logger, XMLParser and CharsetEncoder; method `setCharsetEncoder`
     is now static
   - new methods in helper classes: `Charset::knownCharsets`, `Http::parseAcceptHeader`, `XMLParser::truncateValueForLog`
index 88a9dd6..a3b7eee 100644 (file)
@@ -1009,7 +1009,7 @@ class Client
                 $this->proxy_user,
                 $this->proxy_pass,
                 $this->proxy_authtype,
-                // bc
+                // BC
                 $method == 'http11' ? 'http' : $method,
                 $this->keepalive,
                 $this->key,
@@ -1764,10 +1764,11 @@ class Client
         return $response;
     }
 
-    // BC layer
-
+    // *** BC layer ***
 
     /**
+     * @deprecated
+     *
      * @param Request $req
      * @param string $server
      * @param int $port
@@ -1782,8 +1783,6 @@ class Client
      * @param int $proxyAuthType
      * @param string $method
      * @return Response
-     * @deprecated
-     *
      */
     protected function sendPayloadHTTP10($req, $server, $port, $timeout = 0, $username = '', $password = '',
         $authType = 1, $proxyHost = '', $proxyPort = 0, $proxyUsername = '', $proxyPassword = '', $proxyAuthType = 1,
@@ -1796,6 +1795,8 @@ class Client
     }
 
     /**
+     * @deprecated
+     *
      * @param Request $req
      * @param string $server
      * @param int $port
@@ -1817,8 +1818,6 @@ class Client
      * @param string $keyPass
      * @param int $sslVersion
      * @return Response
-     * @deprecated
-     *
      */
     protected function sendPayloadHTTPS($req, $server, $port, $timeout = 0, $username = '', $password = '',
         $authType = 1, $cert = '', $certPass = '', $caCert = '', $caCertDir = '', $proxyHost = '', $proxyPort = 0,
@@ -1862,6 +1861,8 @@ class Client
         $proxyUsername = '', $proxyPassword = '', $proxyAuthType = 1, $method = 'http', $key = '', $keyPass = '',
         $sslVersion = 0)
     {
+        $this->logDeprecationUnlessCalledBy('send');
+
         return $this->sendViaSocket($req, $method, $server, $port, $this->path, array(
             'accepted_charset_encodings' => $this->accepted_charset_encodings,
             'accepted_compression' => $this->accepted_compression,
@@ -1897,6 +1898,8 @@ class Client
     }
 
     /**
+     * @deprecated
+     *
      * @param Request $req
      * @param string $server
      * @param int $port
@@ -1919,14 +1922,14 @@ class Client
      * @param string $keyPass
      * @param int $sslVersion
      * @return Response
-     * @deprecated
-     *
      */
     protected function sendPayloadCURL($req, $server, $port, $timeout = 0, $username = '', $password = '',
         $authType = 1, $cert = '', $certPass = '', $caCert = '', $caCertDir = '', $proxyHost = '', $proxyPort = 0,
         $proxyUsername = '', $proxyPassword = '', $proxyAuthType = 1, $method = 'https', $keepAlive = false, $key = '',
         $keyPass = '', $sslVersion = 0)
     {
+        $this->logDeprecationUnlessCalledBy('send');
+
         return $this->sendViaCURL($req, $method, $server, $port, $this->path, array(
             'accepted_charset_encodings' => $this->accepted_charset_encodings,
             'accepted_compression' => $this->accepted_compression,
@@ -1992,6 +1995,8 @@ class Client
          $proxyUsername = '', $proxyPassword = '', $proxyAuthType = 1, $method = 'https', $keepAlive = false, $key = '',
          $keyPass = '', $sslVersion = 0)
     {
+        $this->logDeprecationUnlessCalledBy('sendViaCURL');
+
         return $this->createCurlHandle($req, $method, $server, $port, $this->path, array(
             'accepted_charset_encodings' => $this->accepted_charset_encodings,
             'accepted_compression' => $this->accepted_compression,
index a499789..ba971e7 100644 (file)
@@ -16,4 +16,25 @@ trait DeprecationLogger
 
         $this->getLogger()->warning('XML-RPC Deprecated: ' . $message);
     }
+
+    /**
+     * @param string $callee
+     * @param string $expectedCaller atm only the method name is supported
+     * @return void
+     */
+    protected function logDeprecationUnlessCalledBy($expectedCaller)
+    {
+        if (PhpXmlRpc::$xmlrpc_silence_deprecations) {
+            return;
+        }
+
+        $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 3);
+        /// @todo we should check as well $trace[2]['class'], and make sure that it is a descendent of the class passed in in $expectedCaller
+        if ($trace[2]['function'] === $expectedCaller) {
+            return;
+        }
+
+        $this->getLogger()->warning('XML-RPC Deprecated: ' . $trace[1]['class'] . '::' . $trace[1]['function'] .
+            ' is only supposed to be called by ' . $expectedCaller);
+    }
 }
index 9ec2cfc..0a5c7cb 100644 (file)
@@ -255,6 +255,8 @@ class Value implements \Countable, \IteratorAggregate, \ArrayAccess
      */
     protected function serializeData($typ, $val, $charsetEncoding = '')
     {
+        $this->logDeprecationUnlessCalledBy('serialize');
+
         $rs = '';
 
         if (!isset(static::$xmlrpcTypes[$typ])) {
@@ -361,67 +363,6 @@ class Value implements \Countable, \IteratorAggregate, \ArrayAccess
         return '<value>' . $this->serializeData($typ, $val, $charsetEncoding) . "</value>\n";
     }
 
-    /**
-     * Checks whether a struct member with a given name is present.
-     *
-     * Works only on xml-rpc values of type struct.
-     *
-     * @param string $key the name of the struct member to be looked up
-     * @return boolean
-     *
-     * @deprecated use array access, e.g. isset($val[$key])
-     */
-    public function structMemExists($key)
-    {
-        $this->logDeprecation('Method ' . __METHOD__ . ' is deprecated');
-
-        return array_key_exists($key, $this->me['struct']);
-    }
-
-    /**
-     * Returns the value of a given struct member (an xml-rpc value object in itself).
-     * Will raise a php warning if struct member of given name does not exist.
-     *
-     * @param string $key the name of the struct member to be looked up
-     * @return Value
-     *
-     * @deprecated use array access, e.g. $val[$key]
-     */
-    public function structMem($key)
-    {
-        $this->logDeprecation('Method ' . __METHOD__ . ' is deprecated');
-
-        return $this->me['struct'][$key];
-    }
-
-    /**
-     * Reset internal pointer for xml-rpc values of type struct.
-     * @return void
-     *
-     * @deprecated iterate directly over the object using foreach instead
-     */
-    public function structReset()
-    {
-        $this->logDeprecation('Method ' . __METHOD__ . ' is deprecated');
-
-        reset($this->me['struct']);
-    }
-
-    /**
-     * Return next member element for xml-rpc values of type struct.
-     *
-     * @return Value
-     * @throws \Error starting with php 8.0, this function should not be used, as it will always throw
-     *
-     * @deprecated iterate directly over the object using foreach instead
-     */
-    public function structEach()
-    {
-        $this->logDeprecation('Method ' . __METHOD__ . ' is deprecated');
-
-        return @each($this->me['struct']);
-    }
-
     /**
      * Returns the value of a scalar xml-rpc value (base 64 decoding is automatically handled here)
      *
@@ -451,50 +392,6 @@ class Value implements \Countable, \IteratorAggregate, \ArrayAccess
         return $a;
     }
 
-    /**
-     * Returns the m-th member of an xml-rpc value of array type.
-     *
-     * @param integer $key the index of the value to be retrieved (zero based)
-     *
-     * @return Value
-     *
-     * @deprecated use array access, e.g. $val[$key]
-     */
-    public function arrayMem($key)
-    {
-        $this->logDeprecation('Method ' . __METHOD__ . ' is deprecated');
-
-        return $this->me['array'][$key];
-    }
-
-    /**
-     * Returns the number of members in an xml-rpc value of array type.
-     *
-     * @return integer
-     *
-     * @deprecated use count() instead
-     */
-    public function arraySize()
-    {
-        $this->logDeprecation('Method ' . __METHOD__ . ' is deprecated');
-
-        return count($this->me['array']);
-    }
-
-    /**
-     * Returns the number of members in an xml-rpc value of struct type.
-     *
-     * @return integer
-     *
-     * @deprecated use count() instead
-     */
-    public function structSize()
-    {
-        $this->logDeprecation('Method ' . __METHOD__ . ' is deprecated');
-
-        return count($this->me['struct']);
-    }
-
     /**
      * Returns the number of members in an xml-rpc value:
      * - 0 for uninitialized values
@@ -670,4 +567,111 @@ class Value implements \Countable, \IteratorAggregate, \ArrayAccess
                 throw new StateErrorException("XML-RPC Value is of type 'undef' and can not be accessed using array index");
         }
     }
+
+    // *** BC layer ***
+
+    /**
+     * Checks whether a struct member with a given name is present.
+     *
+     * Works only on xml-rpc values of type struct.
+     *
+     * @param string $key the name of the struct member to be looked up
+     * @return boolean
+     *
+     * @deprecated use array access, e.g. isset($val[$key])
+     */
+    public function structMemExists($key)
+    {
+        $this->logDeprecation('Method ' . __METHOD__ . ' is deprecated');
+
+        return array_key_exists($key, $this->me['struct']);
+    }
+
+    /**
+     * Returns the value of a given struct member (an xml-rpc value object in itself).
+     * Will raise a php warning if struct member of given name does not exist.
+     *
+     * @param string $key the name of the struct member to be looked up
+     * @return Value
+     *
+     * @deprecated use array access, e.g. $val[$key]
+     */
+    public function structMem($key)
+    {
+        $this->logDeprecation('Method ' . __METHOD__ . ' is deprecated');
+
+        return $this->me['struct'][$key];
+    }
+
+    /**
+     * Reset internal pointer for xml-rpc values of type struct.
+     * @return void
+     *
+     * @deprecated iterate directly over the object using foreach instead
+     */
+    public function structReset()
+    {
+        $this->logDeprecation('Method ' . __METHOD__ . ' is deprecated');
+
+        reset($this->me['struct']);
+    }
+
+    /**
+     * Return next member element for xml-rpc values of type struct.
+     *
+     * @return Value
+     * @throws \Error starting with php 8.0, this function should not be used, as it will always throw
+     *
+     * @deprecated iterate directly over the object using foreach instead
+     */
+    public function structEach()
+    {
+        $this->logDeprecation('Method ' . __METHOD__ . ' is deprecated');
+
+        return @each($this->me['struct']);
+    }
+
+    /**
+     * Returns the m-th member of an xml-rpc value of array type.
+     *
+     * @param integer $key the index of the value to be retrieved (zero based)
+     *
+     * @return Value
+     *
+     * @deprecated use array access, e.g. $val[$key]
+     */
+    public function arrayMem($key)
+    {
+        $this->logDeprecation('Method ' . __METHOD__ . ' is deprecated');
+
+        return $this->me['array'][$key];
+    }
+
+    /**
+     * Returns the number of members in an xml-rpc value of array type.
+     *
+     * @return integer
+     *
+     * @deprecated use count() instead
+     */
+    public function arraySize()
+    {
+        $this->logDeprecation('Method ' . __METHOD__ . ' is deprecated');
+
+        return count($this->me['array']);
+    }
+
+    /**
+     * Returns the number of members in an xml-rpc value of struct type.
+     *
+     * @return integer
+     *
+     * @deprecated use count() instead
+     */
+    public function structSize()
+    {
+        $this->logDeprecation('Method ' . __METHOD__ . ' is deprecated');
+
+        return count($this->me['struct']);
+    }
 }