From 8ff19d71452c69c294f39971881ffa18036eba16 Mon Sep 17 00:00:00 2001 From: gggeek Date: Wed, 25 Jan 2023 11:39:53 +0000 Subject: [PATCH] move interop error codes to their own class --- src/Helper/Interop.php | 42 ++++++++++++++++++++++++++++++++++++++++++ src/PhpXmlRpc.php | 40 +++++----------------------------------- src/Server.php | 3 ++- 3 files changed, 49 insertions(+), 36 deletions(-) create mode 100644 src/Helper/Interop.php diff --git a/src/Helper/Interop.php b/src/Helper/Interop.php new file mode 100644 index 00000000..e37270c9 --- /dev/null +++ b/src/Helper/Interop.php @@ -0,0 +1,42 @@ + -32601, + 'invalid_return' => 2, + 'incorrect_params' => -32602, + 'introspect_unknown' => -32601, // this shares the same code but has a separate meaning from 'unknown_method'... + 'http_error' => 32300, + 'no_data' => -32700, + 'no_ssl' => -32400, + 'curl_fail' => -32400, + 'invalid_request' => -32600, + 'no_curl' => -32400, + 'server_error' => -32500, + 'multicall_error' => -32700, + 'multicall_notstruct' => -32600, + 'multicall_nomethod' => -32601, + 'multicall_notstring' => -32600, + 'multicall_recursion' => -32603, + 'multicall_noparams' => -32602, + 'multicall_notarray' => -32600, + 'no_http2' => -32400, + 'invalid_xml' => -32700, + 'xml_not_compliant' => -32700, + 'xml_parsing_error' => -32700, + 'cannot_decompress' => -32400, + 'decompress_fail' => -32300, + 'dechunk_fail' => -32300, + 'server_cannot_decompress' => -32300, + 'server_decompress_fail' => -32300, + ); + + public static $xmlrpcerruser = -32000; +} diff --git a/src/PhpXmlRpc.php b/src/PhpXmlRpc.php index 81166bcb..7e43a9cc 100644 --- a/src/PhpXmlRpc.php +++ b/src/PhpXmlRpc.php @@ -4,6 +4,7 @@ namespace PhpXmlRpc; use PhpXmlRpc\Helper\Charset; use PhpXmlRpc\Helper\Http; +use PhpXmlRpc\Helper\Interop; use PhpXmlRpc\Helper\XMLParser; /** @@ -14,7 +15,7 @@ class PhpXmlRpc /** * @var int[] */ - static public $xmlrpcerr = array( + public static $xmlrpcerr = array( 'unknown_method' => 1, /// @deprecated. left in for BC 'invalid_return' => 2, @@ -52,7 +53,7 @@ class PhpXmlRpc /** * @var string[] */ - static public $xmlrpcstr = array( + public static $xmlrpcstr = array( 'unknown_method' => 'Unknown method', /// @deprecated. left in for BC 'invalid_return' => 'Invalid response payload (you can use the setDebug method to allow analysis of the response)', @@ -203,37 +204,6 @@ class PhpXmlRpc */ public static $xmlrpc_methodname_format = '|^[ \t]*[a-zA-Z0-9_.:/]+[ \t]*$|'; - /// @todo review - should we use the range -32099 .. -32000 for some server erors? - public static $xmlrpcerr_interop = array( - 'unknown_method' => -32601, - 'invalid_return' => 2, - 'incorrect_params' => -32602, - 'introspect_unknown' => -32601, // this shares the same code but has a separate meaning from 'unknown_method'... - 'http_error' => 32300, - 'no_data' => -32700, - 'no_ssl' => -32400, - 'curl_fail' => -32400, - 'invalid_request' => -32600, - 'no_curl' => -32400, - 'server_error' => -32500, - 'multicall_error' => -32700, - 'multicall_notstruct' => -32600, - 'multicall_nomethod' => -32601, - 'multicall_notstring' => -32600, - 'multicall_recursion' => -32603, - 'multicall_noparams' => -32602, - 'multicall_notarray' => -32600, - 'no_http2' => -32400, - 'invalid_xml' => -32700, - 'xml_not_compliant' => -32700, - 'xml_parsing_error' => -32700, - 'cannot_decompress' => -32400, - 'decompress_fail' => -32300, - 'dechunk_fail' => -32300, - 'server_cannot_decompress' => -32300, - 'server_decompress_fail' => -32300, - ); - /** * 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... @@ -320,8 +290,8 @@ class PhpXmlRpc */ public static function useInteropFaults() { - self::$xmlrpcerr = self::$xmlrpcerr_interop; + self::$xmlrpcerr = Interop::$xmlrpcerr; - self::$xmlrpcerruser = -32000; + self::$xmlrpcerruser = -Interop::$xmlrpcerruser; } } diff --git a/src/Server.php b/src/Server.php index a5bcb081..5d7b2bbc 100644 --- a/src/Server.php +++ b/src/Server.php @@ -4,6 +4,7 @@ namespace PhpXmlRpc; use PhpXmlRpc\Exception\PhpXmlrpcException; use PhpXmlRpc\Helper\Http; +use PhpXmlRpc\Helper\Interop; use PhpXmlRpc\Helper\Logger; use PhpXmlRpc\Helper\XMLParser; use PhpXmlRpc\Traits\CharsetEncoderAware; @@ -989,7 +990,7 @@ class Server } // support for "standard" error codes - if (PhpXmlRpc::$xmlrpcerr['unknown_method'] == -32601) { + if (PhpXmlRpc::$xmlrpcerr['unknown_method'] === Interop::$xmlrpcerr['unknown_method']) { $outAr['faults_interop'] = array( 'specUrl' => 'http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php', 'specVersion' => 20010516 -- 2.47.0