From afbc3dc926fb4d77708e95459174a9c1f7dea481 Mon Sep 17 00:00:00 2001 From: gggeek Date: Wed, 1 Feb 2023 11:44:34 +0000 Subject: [PATCH] improve .inc shim for recent changes; clearly separate BC support --- lib/xmlrpc.inc | 34 +++++++++++--------- lib/xmlrpc_wrappers.inc | 8 ++--- lib/xmlrpcs.inc | 2 ++ src/Helper/Charset.php | 4 ++- src/Helper/XMLParser.php | 44 +++++++++++++------------- src/PhpXmlRpc.php | 68 +++++++++++++++++++++------------------- src/Response.php | 8 ++--- 7 files changed, 90 insertions(+), 78 deletions(-) diff --git a/lib/xmlrpc.inc b/lib/xmlrpc.inc index 5201320e..b558c5e2 100644 --- a/lib/xmlrpc.inc +++ b/lib/xmlrpc.inc @@ -48,12 +48,7 @@ * 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 '' . $this->serializedata($typ, $val) . "\n"; + return '' . $this->serializeData($typ, $val) . "\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 { diff --git a/lib/xmlrpc_wrappers.inc b/lib/xmlrpc_wrappers.inc index f312fa53..c612a0f3 100644 --- a/lib/xmlrpc_wrappers.inc +++ b/lib/xmlrpc_wrappers.inc @@ -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"; diff --git a/lib/xmlrpcs.inc b/lib/xmlrpcs.inc index 32a2e838..77abb79c 100644 --- a/lib/xmlrpcs.inc +++ b/lib/xmlrpcs.inc @@ -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 */ diff --git a/src/Helper/Charset.php b/src/Helper/Charset.php index 447eaa0b..d4cadd38 100644 --- a/src/Helper/Charset.php +++ b/src/Helper/Charset.php @@ -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 diff --git a/src/Helper/XMLParser.php b/src/Helper/XMLParser.php index bdae23e2..39cb8d0b 100644 --- a/src/Helper/XMLParser.php +++ b/src/Helper/XMLParser.php @@ -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); } } diff --git a/src/PhpXmlRpc.php b/src/PhpXmlRpc.php index e8b8035a..0a5acf50 100644 --- a/src/PhpXmlRpc.php +++ b/src/PhpXmlRpc.php @@ -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; - } } diff --git a/src/Response.php b/src/Response.php index d577bea5..2147179b 100644 --- a/src/Response.php +++ b/src/Response.php @@ -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); } } -- 2.47.0