make XMLParser::$_xh protected
authorgggeek <giunta.gaetano@gmail.com>
Tue, 7 Feb 2023 11:01:41 +0000 (11:01 +0000)
committergggeek <giunta.gaetano@gmail.com>
Tue, 7 Feb 2023 11:01:41 +0000 (11:01 +0000)
NEWS.md
doc/api_changes_v4.10.md
src/Encoder.php
src/Helper/XMLParser.php
src/Request.php
src/Server.php
tests/02ValueTest.php

diff --git a/NEWS.md b/NEWS.md
index e82def1..1f8286c 100644 (file)
--- a/NEWS.md
+++ b/NEWS.md
     and reimplemented the `parse` methods, or wholesale replaced it, you will have to adapt your code: both for that,
     and for making sure that it sets `$this->current_parsing_options['xmlrpc_null_extension']` from
     `PhpXmlRpc::$xmlrpc_null_extension`
-  - also, if you had reimplemented `XMLParser::parse`, be warned that the callers now treat differently results when
-    `_xh['isf'] > 3`
+  - also, if you had reimplemented `XMLParser::parse`, be warned that:
+    - you should return `$this->_xh` instead of void
+    - the callers now treat differently results when `_xh['isf'] > 3`
   - `Client` protected methods `sendPayloadSocket`, `sendPayloadCURL` and `prepareCurlHandle` are now deprecated. They
     have been replaced by `sendViaSocket`, `sendViaCURL` and `createCurlHandle` respectively
   - if you subclassed the `Client` class, take care of new static variables `$requestClass` and `$responseClass`,
index d60ef23..0a4d969 100644 (file)
@@ -56,6 +56,7 @@ implementation clashes with the new one if you implemented:
 | Response  | getPayload          |           |
 | Response  | valueType           |           |
 | Response  | xml_header          |           |
+| Server    | addToMap            |           |
 | Server    | getOption           |           |
 | Server    | getOptions          |           |
 | Server    | setDispatchMap      |           |
@@ -128,9 +129,10 @@ The following methods have had some parameters deprecated
 
 The following methods have modified their return value
 
-| Class     | Method         | Notes   |
-|-----------|----------------|---------|
-| Client    | _try_multicall | private |
+| Class     | Method         | Notes                               |
+|-----------|----------------|-------------------------------------|
+| Client    | _try_multicall | private                             |
+| XMLParser | parse          | was: return void, now returns array |
 
 Deprecated methods
 ------------------
@@ -157,64 +159,65 @@ Deprecated properties
 
 The following properties have now protected access. Replacement accessor for public use are listed.
 
-| Class    | Property                   | Read via               | Write via                        |
-|----------|----------------------------|------------------------|----------------------------------|
-| Client   | accepted_charset_encodings | getOption              | setOption                        |
-| Client   | accepted_compression       | getOption              | setOption/setAcceptedCompression |
-| Client   | authtype                   | getOption              | setOption/setCredentials         |
-| Client   | cacert                     | getOption              | setOption/setCaCertificate       |
-| Client   | cacertdir                  | getOption              | setOption/setCaCertificate       |
-| Client   | cert                       | getOption              | setOption/setCertificate         |
-| Client   | certpass                   | getOption              | setOption/setCertificate         |
-| Client   | cookies                    | getOption              | setOption                        |
-| Client   | debug                      | getOption              | setOption/setDebug               |
-| Client   | errno                      | -                      | -                                |
-| Client   | errstr                     | -                      | -                                |
-| Client   | extracurlopts              | getOption              | setOption                        |
-| Client   | keepalive                  | getOption              | setOption                        |
-| Client   | key                        | getOption              | setOption/setKey                 |
-| Client   | keypass                    | getOption              | setOption/setKey                 |
-| Client   | method                     | getUrl                 | __construct                      |
-| Client   | no_multicall               | getOption              | setOption                        |
-| Client   | password                   | getOption              | setOption/setCredentials         |
-| Client   | path                       | getUrl                 | __construct                      |
-| Client   | port                       | getUrl                 | __construct                      |
-| Client   | proxy                      | getOption              | setOption/setProxy               |
-| Client   | proxy_authtype             | getOption              | setOption/setProxy               |
-| Client   | proxy_pass                 | getOption              | setOption/setProxy               |
-| Client   | proxy_user                 | getOption              | setOption/setProxy               |
-| Client   | proxyport                  | getOption              | setOption/setProxy               |
-| Client   | request_charset_encoding   | getOption              | setOption                        |
-| Client   | request_compression        | getOption              | setOption                        |
-| Client   | return_type                | getOption              | setOption                        |
-| Client   | server                     | getUrl                 | __construct                      |
-| Client   | sslversion                 | getOption              | setOption                        |
-| Client   | use_curl                   | getOption              | setOption                        |
-| Client   | user_agent                 | getOption              | setOption                        |
-| Client   | username                   | getOption              | setOption/setCredentials         |
-| Client   | verifyhost                 | getOption              | setOption                        |
-| Client   | verifypeer                 | getOption              | setOption                        |
-| Request  | content_type               | getContentType         | setPayload                       |
-| Request  | debug                      | setDebug               | -                                |
-| Request  | methodname                 | method                 | __construct/method               |
-| Request  | params                     | getParam               | __construct/addParam             |
-| Request  | payload                    | getPayload             | setPayload                       |
-| Response | val                        | value                  | __construct                      |
-| Response | valtyp                     | valueType              | __construct                      |
-| Response | errno                      | faultCode              | __construct                      |
-| Response | errstr                     | faultString            | __construct                      |
-| Response | content_type               | getContentType         | setPayload                       |
-| Response | payload                    | getPayload             | setPayload                       |
-| Server   | accepted_charset_encodings | -                      | -                                |
-| Server   | accepted_compression       | getOption              | setOption                        |
-| Server   | allow_system_funcs         | getOption              | setOption                        |
-| Server   | compress_response          | getOption              | setOption                        |
-| Server   | debug                      | getOption              | setOption/setDebug               |
-| Server   | exception_handling         | getOption              | setOption                        |
-| Server   | functions_parameters_type  | getOption              | setOption                        |
-| Server   | phpvals_encoding_options   | getOption              | setOption                        |
-| Server   | response_charset_encoding  | getOption              | setOption                        |
-| Value    | _php_class                 | -                      | -                                |
-| Value    | me                         | scalarVal/array access | __construct                      |
-| Value    | mytype                     | kindOf                 | __construct                      |
-| Wrapper  | $objectholder              | getHeldObject          | holdObject                       |
+| Class     | Property                   | Read via               | Write via                        |
+|-----------|----------------------------|------------------------|----------------------------------|
+| Client    | accepted_charset_encodings | getOption              | setOption                        |
+| Client    | accepted_compression       | getOption              | setOption/setAcceptedCompression |
+| Client    | authtype                   | getOption              | setOption/setCredentials         |
+| Client    | cacert                     | getOption              | setOption/setCaCertificate       |
+| Client    | cacertdir                  | getOption              | setOption/setCaCertificate       |
+| Client    | cert                       | getOption              | setOption/setCertificate         |
+| Client    | certpass                   | getOption              | setOption/setCertificate         |
+| Client    | cookies                    | getOption              | setOption                        |
+| Client    | debug                      | getOption              | setOption/setDebug               |
+| Client    | errno                      | -                      | -                                |
+| Client    | errstr                     | -                      | -                                |
+| Client    | extracurlopts              | getOption              | setOption                        |
+| Client    | keepalive                  | getOption              | setOption                        |
+| Client    | key                        | getOption              | setOption/setKey                 |
+| Client    | keypass                    | getOption              | setOption/setKey                 |
+| Client    | method                     | getUrl                 | __construct                      |
+| Client    | no_multicall               | getOption              | setOption                        |
+| Client    | password                   | getOption              | setOption/setCredentials         |
+| Client    | path                       | getUrl                 | __construct                      |
+| Client    | port                       | getUrl                 | __construct                      |
+| Client    | proxy                      | getOption              | setOption/setProxy               |
+| Client    | proxy_authtype             | getOption              | setOption/setProxy               |
+| Client    | proxy_pass                 | getOption              | setOption/setProxy               |
+| Client    | proxy_user                 | getOption              | setOption/setProxy               |
+| Client    | proxyport                  | getOption              | setOption/setProxy               |
+| Client    | request_charset_encoding   | getOption              | setOption                        |
+| Client    | request_compression        | getOption              | setOption                        |
+| Client    | return_type                | getOption              | setOption                        |
+| Client    | server                     | getUrl                 | __construct                      |
+| Client    | sslversion                 | getOption              | setOption                        |
+| Client    | use_curl                   | getOption              | setOption                        |
+| Client    | user_agent                 | getOption              | setOption                        |
+| Client    | username                   | getOption              | setOption/setCredentials         |
+| Client    | verifyhost                 | getOption              | setOption                        |
+| Client    | verifypeer                 | getOption              | setOption                        |
+| Request   | content_type               | getContentType         | setPayload                       |
+| Request   | debug                      | setDebug               | -                                |
+| Request   | methodname                 | method                 | __construct/method               |
+| Request   | params                     | getParam               | __construct/addParam             |
+| Request   | payload                    | getPayload             | setPayload                       |
+| Response  | val                        | value                  | __construct                      |
+| Response  | valtyp                     | valueType              | __construct                      |
+| Response  | errno                      | faultCode              | __construct                      |
+| Response  | errstr                     | faultString            | __construct                      |
+| Response  | content_type               | getContentType         | setPayload                       |
+| Response  | payload                    | getPayload             | setPayload                       |
+| Server    | accepted_charset_encodings | -                      | -                                |
+| Server    | accepted_compression       | getOption              | setOption                        |
+| Server    | allow_system_funcs         | getOption              | setOption                        |
+| Server    | compress_response          | getOption              | setOption                        |
+| Server    | debug                      | getOption              | setOption/setDebug               |
+| Server    | exception_handling         | getOption              | setOption                        |
+| Server    | functions_parameters_type  | getOption              | setOption                        |
+| Server    | phpvals_encoding_options   | getOption              | setOption                        |
+| Server    | response_charset_encoding  | getOption              | setOption                        |
+| Value     | _php_class                 | -                      | -                                |
+| Value     | me                         | scalarVal/array access | __construct                      |
+| Value     | mytype                     | kindOf                 | __construct                      |
+| Wrapper   | $objectholder              | getHeldObject          | holdObject                       |
+| XMLParser | $_xh                       | results of parse()     | -                                |
index 6128492..17c14b1 100644 (file)
@@ -325,13 +325,16 @@ class Encoder
         }
 
         $xmlRpcParser = $this->getParser();
-        $xmlRpcParser->parse(
+        $_xh = $xmlRpcParser->parse(
             $xmlVal,
             XMLParser::RETURN_XMLRPCVALS,
             XMLParser::ACCEPT_REQUEST | XMLParser::ACCEPT_RESPONSE | XMLParser::ACCEPT_VALUE | XMLParser::ACCEPT_FAULT,
             $parserOptions
         );
-        $_xh = $xmlRpcParser->_xh;
+        // BC
+        if (!is_array($_xh)) {
+            $_xh = $xmlRpcParser->_xh;
+        }
 
         if ($_xh['isf'] > 1) {
             // test that $_xh['value'] is an obj, too???
index 167a880..c23b6fc 100644 (file)
@@ -59,7 +59,7 @@ class XMLParser
      *    pt - used to store the type of each received parameter. Useful if parameters are automatically decoded to php values
      *    rt - 'methodcall', 'methodresponse', 'value' or 'fault' (the last one used only in EPI emulation mode)
      */
-    public $_xh = array(
+    protected $_xh = array(
         'ac' => '',
         'stack' => array(),
         'valuestack' => array(),
@@ -144,7 +144,7 @@ class XMLParser
      *                       These options are added to options received in the constructor.
      *                       Note that if options xmlrpc_null_extension, xmlrpc_return_datetimes and xmlrpc_reject_invalid_values
      *                       are not set, the default settings from PhpXmlRpc\PhpXmlRpc are used
-     * @return void the caller has to look into $this->_xh to find the results
+     * @return array see the definition of $this->_xh for the meaning of the results
      * @throws \Exception this can happen if a callback function is set and it does throw (i.e. we do not catch exceptions)
      *
      * @todo refactor? we could 1. return the parsed data structure, and 2. move $returnType and $accept into options
@@ -173,7 +173,7 @@ class XMLParser
         if ($len == 0) {
             $this->_xh['isf'] = 3;
             $this->_xh['isf_reason'] = 'XML error 5: empty document';
-            return;
+            return $this->_xh;
         }
 
         $this->current_parsing_options = array('accept' => $accept);
@@ -289,6 +289,8 @@ class XMLParser
 
         xml_parser_free($parser);
         $this->current_parsing_options = array();
+
+        return $this->_xh;
     }
 
     /**
@@ -1020,6 +1022,7 @@ class XMLParser
     public function &__get($name)
     {
         switch ($name) {
+            case '_xh':
             case 'xmlrpc_valid_parents':
                 $this->logDeprecation('Getting property XMLParser::' . $name . ' is deprecated');
                 return $this->$name;
@@ -1040,6 +1043,7 @@ class XMLParser
                 $this->logDeprecation('Setting property XMLParser::' . $name . ' is deprecated');
                 $this->current_parsing_options['accept'] = $value;
                 break;
+            case '_xh':
             case 'xmlrpc_valid_parents':
                 $this->logDeprecation('Setting property XMLParser::' . $name . ' is deprecated');
                 $this->$name = $value;
@@ -1057,6 +1061,7 @@ class XMLParser
             case 'accept':
                 $this->logDeprecation('Checking property XMLParser::' . $name . ' is deprecated');
                 return isset($this->current_parsing_options['accept']);
+            case '_xh':
             case 'xmlrpc_valid_parents':
                 $this->logDeprecation('Checking property XMLParser::' . $name . ' is deprecated');
                 return isset($this->$name);
@@ -1073,6 +1078,7 @@ class XMLParser
                 $this->logDeprecation('Unsetting property XMLParser::' . $name . ' is deprecated');
                 unset($this->current_parsing_options['accept']);
                 break;
+            case '_xh':
             case 'xmlrpc_valid_parents':
                 $this->logDeprecation('Unsetting property XMLParser::' . $name . ' is deprecated');
                 unset($this->$name);
index c1248f8..ace63df 100644 (file)
@@ -323,8 +323,11 @@ class Request
         }
 
         $xmlRpcParser = $this->getParser();
-        $xmlRpcParser->parse($data, $returnType, XMLParser::ACCEPT_RESPONSE, $options);
-        $_xh = $xmlRpcParser->_xh;
+        $_xh = $xmlRpcParser->parse($data, $returnType, XMLParser::ACCEPT_RESPONSE, $options);
+        // BC
+        if (!is_array($_xh)) {
+            $_xh = $xmlRpcParser->_xh;
+        }
 
         // first error check: xml not well-formed
         if ($_xh['isf'] == 3) {
index a882f64..d9c91fb 100644 (file)
@@ -706,8 +706,11 @@ class Server
 
         $xmlRpcParser = $this->getParser();
         try {
-            $xmlRpcParser->parse($data, $this->functions_parameters_type, XMLParser::ACCEPT_REQUEST, $options);
-            $_xh = $xmlRpcParser->_xh;
+            $_xh = $xmlRpcParser->parse($data, $this->functions_parameters_type, XMLParser::ACCEPT_REQUEST, $options);
+            // BC
+            if (!is_array($_xh)) {
+                $_xh = $xmlRpcParser->_xh;
+            }
         } catch (NoSuchMethodException $e) {
             return new Response(0, $e->getCode(), $e->getMessage());
         }
index 7cd92a4..654a5bc 100644 (file)
@@ -205,9 +205,9 @@ class ValueTest extends PhpXmlRpc_LoggerAwareTestCase
         $req = new \PhpXmlRpc\Request('test', array($val));
         $xml = $req->serialize();
         $parser = new \PhpXmlRpc\Helper\XMLParser();
-        $parser->parse($xml);
+        $_xh = $parser->parse($xml);
 
-        $this->assertequals(0, $parser->_xh['isf']);
+        $this->assertequals(0, $_xh['isf']);
     }
 
     public function testLatin15InternalEncoding()