From b3aa53c16d6bc559a7e87be6fbcbf815e5dc4534 Mon Sep 17 00:00:00 2001 From: gggeek Date: Tue, 7 Feb 2023 11:01:41 +0000 Subject: [PATCH] make XMLParser::$_xh protected --- NEWS.md | 5 +- doc/api_changes_v4.10.md | 131 ++++++++++++++++++++------------------- src/Encoder.php | 7 ++- src/Helper/XMLParser.php | 12 +++- src/Request.php | 7 ++- src/Server.php | 7 ++- tests/02ValueTest.php | 4 +- 7 files changed, 96 insertions(+), 77 deletions(-) diff --git a/NEWS.md b/NEWS.md index e82def18..1f8286ce 100644 --- a/NEWS.md +++ b/NEWS.md @@ -183,8 +183,9 @@ 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`, diff --git a/doc/api_changes_v4.10.md b/doc/api_changes_v4.10.md index d60ef23f..0a4d969f 100644 --- a/doc/api_changes_v4.10.md +++ b/doc/api_changes_v4.10.md @@ -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() | - | diff --git a/src/Encoder.php b/src/Encoder.php index 6128492b..17c14b16 100644 --- a/src/Encoder.php +++ b/src/Encoder.php @@ -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??? diff --git a/src/Helper/XMLParser.php b/src/Helper/XMLParser.php index 167a8807..c23b6fc5 100644 --- a/src/Helper/XMLParser.php +++ b/src/Helper/XMLParser.php @@ -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); diff --git a/src/Request.php b/src/Request.php index c1248f8a..ace63df4 100644 --- a/src/Request.php +++ b/src/Request.php @@ -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) { diff --git a/src/Server.php b/src/Server.php index a882f642..d9c91fbf 100644 --- a/src/Server.php +++ b/src/Server.php @@ -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()); } diff --git a/tests/02ValueTest.php b/tests/02ValueTest.php index 7cd92a43..654a5bca 100644 --- a/tests/02ValueTest.php +++ b/tests/02ValueTest.php @@ -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() -- 2.47.0