improve .inc shim for recent changes; clearly separate BC support
authorgggeek <giunta.gaetano@gmail.com>
Wed, 1 Feb 2023 11:44:34 +0000 (11:44 +0000)
committergggeek <giunta.gaetano@gmail.com>
Wed, 1 Feb 2023 11:44:34 +0000 (11:44 +0000)
lib/xmlrpc.inc
lib/xmlrpc_wrappers.inc
lib/xmlrpcs.inc
src/Helper/Charset.php
src/Helper/XMLParser.php
src/PhpXmlRpc.php
src/Response.php

index 5201320..b558c5e 100644 (file)
  * file api_changes_v4.md for how to change this if required.
  *****************************************************************************/
 
-include_once(__DIR__.'/../src/Client.php');
-include_once(__DIR__.'/../src/Encoder.php');
-include_once(__DIR__.'/../src/PhpXmlRpc.php');
-include_once(__DIR__.'/../src/Request.php');
-include_once(__DIR__.'/../src/Response.php');
-include_once(__DIR__.'/../src/Value.php');
+// the list is sorted more-or-less in dependency order
 include_once(__DIR__.'/../src/Exception.php');
 include_once(__DIR__.'/../src/Exception/FaultResponseException.php');
 include_once(__DIR__.'/../src/Exception/ParsingException.php');
@@ -66,11 +61,22 @@ include_once(__DIR__.'/../src/Exception/NoSuchMethodException.php');
 include_once(__DIR__.'/../src/Exception/StateErrorException.php');
 include_once(__DIR__.'/../src/Exception/TypeErrorException.php');
 include_once(__DIR__.'/../src/Exception/ValueErrorException.php');
+include_once(__DIR__.'/../src/PhpXmlRpc.php');
 include_once(__DIR__.'/../src/Helper/Charset.php');
 include_once(__DIR__.'/../src/Helper/Date.php');
 include_once(__DIR__.'/../src/Helper/Http.php');
+include_once(__DIR__.'/../src/Helper/Interop.php');
 include_once(__DIR__.'/../src/Helper/Logger.php');
 include_once(__DIR__.'/../src/Helper/XMLParser.php');
+include_once(__DIR__.'/../src/Traits/CharsetEncoderAware.php');
+include_once(__DIR__.'/../src/Traits/LoggerAware.php');
+include_once(__DIR__.'/../src/Traits/DeprecationLogger.php');
+include_once(__DIR__.'/../src/Traits/ParserAware.php');
+include_once(__DIR__.'/../src/Value.php');
+include_once(__DIR__.'/../src/Request.php');
+include_once(__DIR__.'/../src/Response.php');
+include_once(__DIR__.'/../src/Client.php');
+include_once(__DIR__.'/../src/Encoder.php');
 
 use PhpXmlRpc\Client;
 use PhpXmlRpc\Encoder;
@@ -105,7 +111,7 @@ $GLOBALS['xmlrpc_backslash'] = chr(92).chr(92);
 /* Expose with the old names the classes which have been namespaced */
 
 /**
- * @todo reinstate access to method serializedata ?
+ * @todo reinstate access to method serializeData?
  */
 class xmlrpcval extends Value
 {
@@ -123,13 +129,13 @@ class xmlrpcval extends Value
         $val = reset($ar);
         $typ = key($ar);
 
-        return '<value>' . $this->serializedata($typ, $val) . "</value>\n";
+        return '<value>' . $this->serializeData($typ, $val) . "</value>\n";
         //}
     }
 
     /**
-     * @deprecated this code looks like it is very fragile and has not been fixed
-     * for a long long time. Shall we remove it for 2.0?
+     * @deprecated this code looks like it is very fragile and has not been fixed for a long long time.
+     * Shall we remove it for 2.0?
      */
     public function getval()
     {
@@ -143,7 +149,7 @@ class xmlrpcval extends Value
 
         if (is_array($b)) {
             foreach($b as $id => $cont) {
-                $b[$id] = $cont->scalarval();
+                $b[$id] = $cont->scalarVal();
             }
         }
 
@@ -151,7 +157,7 @@ class xmlrpcval extends Value
         if (is_object($b)) {
             $t = get_object_vars($b);
             foreach($t as $id => $cont) {
-                $t[$id] = $cont->scalarval();
+                $t[$id] = $cont->scalarVal();
             }
             foreach($t as $id => $cont) {
                 @$b->$id = $cont;
@@ -175,7 +181,7 @@ class xmlrpcval extends Value
 }
 
 /**
- * @todo reinstate access to method parseResponseHeaders ?
+ * @todo reinstate access to method parseResponseHeaders?
  */
 class xmlrpcmsg extends Request
 {
@@ -186,7 +192,7 @@ class xmlrpcresp extends Response
 }
 
 /**
- * @todo reinstate access to methods sendPayloadHTTP10, sendPayloadHTTPS, sendPayloadCURL, _try_multicall ?
+ * @todo reinstate access to methods sendPayloadHTTP10, sendPayloadHTTPS, sendPayloadCURL, _try_multicall?
  */
 class xmlrpc_client extends Client
 {
index f312fa5..c612a0f 100644 (file)
@@ -44,7 +44,7 @@ function xmlrpc_2_php_type($xmlrpcType)
 function wrap_php_function($funcName, $newFuncName='', $extraOptions=array())
 {
     $wrapper = new PhpXmlRpc\Wrapper();
-    if (!isset($extraOptions['return_source'])  || $extraOptions['return_source'] == false) {
+    if (!isset($extraOptions['return_source']) || $extraOptions['return_source'] == false) {
         // backwards compat: return string instead of callable
         $extraOptions['return_source'] = true;
         $wrapped = $wrapper->wrapPhpFunction($funcName, $newFuncName, $extraOptions);
@@ -68,7 +68,7 @@ function wrap_php_class($className, $extraOptions=array())
 {
     $wrapper = new PhpXmlRpc\Wrapper();
     $fix = false;
-    if (!isset($extraOptions['return_source'])  || $extraOptions['return_source'] == false) {
+    if (!isset($extraOptions['return_source']) || $extraOptions['return_source'] == false) {
         // backwards compat: return string instead of callable
         $extraOptions['return_source'] = true;
         $fix = true;
@@ -207,9 +207,9 @@ function build_remote_method_wrapper_code($client, $methodName, $xmlrpcFuncName,
         $respCode = '$res';
     }
     if ($decodePhpObjects) {
-        $innerCode .= "if (\$res->faultcode()) return $respCode; else return \$encoder->decode(\$res->value(), array('decode_php_objs'));";
+        $innerCode .= "if (\$res->faultCode()) return $respCode; else return \$encoder->decode(\$res->value(), array('decode_php_objs'));";
     } else {
-        $innerCode .= "if (\$res->faultcode()) return $respCode; else return \$encoder->decode(\$res->value());";
+        $innerCode .= "if (\$res->faultCode()) return $respCode; else return \$encoder->decode(\$res->value());";
     }
 
     $code = $code . $plist . ") {\n" . $innerCode . "\n}\n";
index 32a2e83..77abb79 100644 (file)
@@ -84,6 +84,8 @@ class xmlrpc_server extends Server
     {
         return $name === 'dmap';
     }
+
+    /// @todo what about __set, __unset?
 }
 
 /* Expose as global functions the ones which are now class methods */
index 447eaa0..d4cadd3 100644 (file)
@@ -340,6 +340,8 @@ class Charset
         return $knownCharsets;
     }
 
+    // *** BC layer ***
+
     /**
      * Checks if a given charset encoding is present in a list of encodings or if it is a valid subset of any encoding
      * in the list.
@@ -372,7 +374,7 @@ class Charset
     }
 
     /**
-     * Used only for backwards compatibility.
+     * Used only for backwards compatibility (the .inc shims).
      * @deprecated
      *
      * @param string $charset
index bdae23e..39cb8d0 100644 (file)
@@ -479,24 +479,6 @@ class XMLParser
         }
     }
 
-    /**
-     * xml parser handler function for opening element tags.
-     * Used in decoding xml chunks that might represent single xml-rpc values as well as requests, responses.
-     * @deprecated
-     *
-     * @param resource $parser
-     * @param $name
-     * @param $attrs
-     * @return void
-     */
-    public function xmlrpc_se_any($parser, $name, $attrs)
-    {
-        // avoid spamming the log with warnings in case this is in use...
-        //$this->logDeprecation('Method ' . __METHOD__ . ' is deprecated');
-
-        $this->xmlrpc_se($parser, $name, $attrs, true);
-    }
-
     /**
      * xml parser handler function for close element tags.
      * @internal
@@ -831,7 +813,7 @@ class XMLParser
 
     /**
      * xml parser handler function for 'other stuff', i.e. not char data or element start/end tag.
-     * In fact it only gets called on unknown entities...
+     * In fact, it only gets called on unknown entities...
      * @internal
      *
      * @param $parser
@@ -1013,7 +995,25 @@ class XMLParser
         return $data;
     }
 
-    // BC layer
+    // *** BC layer ***
+
+    /**
+     * xml parser handler function for opening element tags.
+     * Used in decoding xml chunks that might represent single xml-rpc values as well as requests, responses.
+     * @deprecated
+     *
+     * @param resource $parser
+     * @param $name
+     * @param $attrs
+     * @return void
+     */
+    public function xmlrpc_se_any($parser, $name, $attrs)
+    {
+        // this will be spamming the log if this method is in use...
+        $this->logDeprecation('Method ' . __METHOD__ . ' is deprecated');
+
+        $this->xmlrpc_se($parser, $name, $attrs, true);
+    }
 
     public function __set($name, $value)
     {
@@ -1025,7 +1025,7 @@ class XMLParser
                 break;
             default:
                 /// @todo throw instead? There are very few other places where the lib trigger errors which can potentially reach stdout...
-                $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
+                $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1);
                 trigger_error('Undefined property via __set(): ' . $name . ' in ' . $trace[0]['file'] . ' on line ' . $trace[0]['line'], E_USER_WARNING);
         }
     }
@@ -1051,7 +1051,7 @@ class XMLParser
                 break;
             default:
                 /// @todo throw instead? There are very few other places where the lib trigger errors which can potentially reach stdout...
-                $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
+                $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1);
                 trigger_error('Undefined property via __unset(): ' . $name . ' in ' . $trace[0]['file'] . ' on line ' . $trace[0]['line'], E_USER_WARNING);
         }
     }
index e8b8035..0a5acf5 100644 (file)
@@ -213,6 +213,41 @@ class PhpXmlRpc
      */
     public static $xmlrpc_silence_deprecations = true;
 
+    // *** BC layer ***
+
+    /**
+     * Inject a logger into all classes of the PhpXmlRpc library which use one
+     *
+     * @param $logger
+     * @return void
+     */
+    public static function setLogger($logger)
+    {
+        Charset::setLogger($logger);
+        Client::setLogger($logger);
+        Encoder::setLogger($logger);
+        Http::setLogger($logger);
+        Request::setLogger($logger);
+        Server::setLogger($logger);
+        Value::setLogger($logger);
+        Wrapper::setLogger($logger);
+        XMLParser::setLogger($logger);
+    }
+
+    /**
+     * Makes the library use the error codes detailed at https://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php
+     *
+     * @return void
+     *
+     * @tofo feature creep - allow switching back to the original set of codes; querying the current mode
+     */
+    public static function useInteropFaults()
+    {
+        self::$xmlrpcerr = Interop::$xmlrpcerr;
+
+        self::$xmlrpcerruser = -Interop::$xmlrpcerruser;
+    }
+
     /**
      * A function to be used for compatibility with legacy code: it creates all global variables which used to be declared,
      * such as library version etc...
@@ -274,37 +309,4 @@ class PhpXmlRpc
             }
         }
     }
-
-    /**
-     * Inject a logger into all classes of the PhpXmlRpc library which use one
-     *
-     * @param $logger
-     * @return void
-     */
-    public static function setLogger($logger)
-    {
-        Charset::setLogger($logger);
-        Client::setLogger($logger);
-        Encoder::setLogger($logger);
-        Http::setLogger($logger);
-        Request::setLogger($logger);
-        Server::setLogger($logger);
-        Value::setLogger($logger);
-        Wrapper::setLogger($logger);
-        XMLParser::setLogger($logger);
-    }
-
-    /**
-     * Makes the library use the error codes detailed at https://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php
-     *
-     * @return void
-     *
-     * @tofo feature creep - allow switching back to the original set of codes; querying the current mode
-     */
-    public static function useInteropFaults()
-    {
-        self::$xmlrpcerr = Interop::$xmlrpcerr;
-
-        self::$xmlrpcerruser = -Interop::$xmlrpcerruser;
-    }
 }
index d577bea..2147179 100644 (file)
@@ -189,7 +189,7 @@ class Response
         return $result;
     }
 
-    // BC layer
+    // *** BC layer ***
 
     // we have to make this return by ref in order to allow calls such as `$resp->_cookies['name'] = ['value' => 'something'];`
     public function &__get($name)
@@ -206,7 +206,7 @@ class Response
                 return $this->httpResponse['raw_data'];
             default:
                 /// @todo throw instead? There are very few other places where the lib trigger errors which can potentially reach stdout...
-                $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
+                $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1);
                 trigger_error('Undefined property via __get(): ' . $name . ' in ' . $trace[0]['file'] . ' on line ' . $trace[0]['line'], E_USER_WARNING);
                 return null;
         }
@@ -229,7 +229,7 @@ class Response
                 break;
             default:
                 /// @todo throw instead? There are very few other places where the lib trigger errors which can potentially reach stdout...
-                $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
+                $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1);
                 trigger_error('Undefined property via __set(): ' . $name . ' in ' . $trace[0]['file'] . ' on line ' . $trace[0]['line'], E_USER_WARNING);
         }
     }
@@ -268,7 +268,7 @@ class Response
                 break;
             default:
                 /// @todo throw instead? There are very few other places where the lib trigger errors which can potentially reach stdout...
-                $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
+                $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1);
                 trigger_error('Undefined property via __unset(): ' . $name . ' in ' . $trace[0]['file'] . ' on line ' . $trace[0]['line'], E_USER_WARNING);
         }
     }