From: gggeek Date: Sun, 14 Dec 2014 23:23:23 +0000 (+0000) Subject: WIP fix bugs after introduction of namespaces, found trying to run the testsuite X-Git-Tag: 4.0.0-alpha^2~202 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=e2ef0823a57f66ef5260006a2d08528428457c84;p=plcapi.git WIP fix bugs after introduction of namespaces, found trying to run the testsuite --- diff --git a/debugger/action.php b/debugger/action.php index f56946c..fae2065 100644 --- a/debugger/action.php +++ b/debugger/action.php @@ -149,10 +149,10 @@ td form {margin: 0;} switch ($action) { case 'wrap': - @include('xmlrpc_wrappers.php'); + @include('xmlrpc_wrappers.inc'); if (!function_exists('build_remote_method_wrapper_code')) { - die('Error: to enable creation of method stubs the xmlrpc_wrappers.php file is needed'); + die('Error: to enable creation of method stubs the xmlrpc_wrappers.inc file is needed'); } // fall thru intentionally case 'describe': diff --git a/demo/client/wrap.php b/demo/client/wrap.php index faae4bf..8ec452c 100644 --- a/demo/client/wrap.php +++ b/demo/client/wrap.php @@ -9,7 +9,7 @@ return_type = 'phpvals'; // let client give us back php values instead of xmlrpcvals diff --git a/demo/server/server.php b/demo/server/server.php index d17f73c..853dc4b 100644 --- a/demo/server/server.php +++ b/demo/server/server.php @@ -19,7 +19,7 @@ if ($_SERVER['REQUEST_METHOD'] != 'POST' && isset($_GET['showSource'])) include("xmlrpc.inc"); include("xmlrpcs.inc"); - include("xmlrpc_wrappers.php"); + include("xmlrpc_wrappers.inc"); /** * Used to test usage of object methods in dispatch maps and in wrapper code diff --git a/lib/xmlrpc.inc b/lib/xmlrpc.inc index c706758..57a0adc 100644 --- a/lib/xmlrpc.inc +++ b/lib/xmlrpc.inc @@ -49,6 +49,10 @@ include_once(__DIR__.'/../src/Response.php'); include_once(__DIR__.'/../src/Client.php'); include_once(__DIR__.'/../src/Encoder.php'); + +/* Expose the global variables which used to be defined */ +PhpXmlRpc\PhpXmlRpc::exportGlobals(); + /* Expose with the old names the classes which have been namespaced */ class xmlrpcval extends PhpXmlRpc\Value diff --git a/src/Encoder.php b/src/Encoder.php index f464f82..d687467 100644 --- a/src/Encoder.php +++ b/src/Encoder.php @@ -185,7 +185,7 @@ class Encoder } break; case 'object': - if(is_a($php_val, 'xmlrpcval')) + if(is_a($php_val, 'PhpXmlRpc\Value')) { $xmlrpc_val = $php_val; } diff --git a/src/PhpXmlRpc.php b/src/PhpXmlRpc.php index 201ba63..dc0c4ab 100644 --- a/src/PhpXmlRpc.php +++ b/src/PhpXmlRpc.php @@ -83,4 +83,39 @@ class PhpXmlRpc public static $xmlrpc_null_apache_encoding = false; public static $xmlrpc_null_apache_encoding_ns = "http://ws.apache.org/xmlrpc/namespaces/extensions"; + + /** + * 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... + */ + public static function exportGlobals() + { + $reflection = new \ReflectionClass('PhpXmlRpc\PhpXmlRpc'); + $staticProperties = $reflection->getStaticProperties(); + foreach ($staticProperties as $name => $value) + { + $GLOBALS[$name] = $value; + } + } + + /** + * A function to be used for compatibility with legacy code: it gets the values of all global variables which used + * to be declared, such as library version etc... and sets them to php classes. + * It should be used by code which changed the values of those global variables to alter the working of the library. + * Example code: + * 1. include xmlrpc.inc + * 2. set the values, e.g. $GLOBALS['xmlrpc_internalencoding'] = 'UTF-8'; + * 3. import them: PhpXmlRpc\PhpXmlRpc::importGlobals(); + * 4. run your own code + */ + public static function importGlobals() + { + $reflection = new \ReflectionClass('PhpXmlRpc\PhpXmlRpc'); + $staticProperties = $reflection->getStaticProperties(); + foreach ($staticProperties as $name => $value) + { + if(isset($GLOBALS[$name])) + self::$$name = $GLOBALS[$name]; + } + } } diff --git a/src/Response.php b/src/Response.php index 5f0f6ec..bd205a8 100644 --- a/src/Response.php +++ b/src/Response.php @@ -139,7 +139,7 @@ Charset::instance()->encode_entitites($this->errstr, PhpXmlRpc::$xmlrpc_internal } else { - if(!is_object($this->val) || !is_a($this->val, 'xmlrpcval')) + if(!is_object($this->val) || !is_a($this->val, 'PhpXmlRpc\Value')) { if (is_string($this->val) && $this->valtyp == 'xml') { diff --git a/src/Server.php b/src/Server.php index a3cde97..74acb06 100644 --- a/src/Server.php +++ b/src/Server.php @@ -740,7 +740,7 @@ class Server if (!is_a($r, 'xmlrpcresp')) { error_log("XML-RPC: ".__METHOD__.": function $func registered as method handler does not return an xmlrpcresp object"); - if (is_a($r, 'xmlrpcval')) + if (is_a($r, 'PhpXmlRpc\Value')) { $r = new Response($r); } diff --git a/src/Value.php b/src/Value.php index fd4a840..04df2eb 100644 --- a/src/Value.php +++ b/src/Value.php @@ -130,10 +130,10 @@ class Value switch($this->mytype) { case 1: - error_log('XML-RPC: '.__METHOD__.': scalar xmlrpcval can have only one value'); + error_log('XML-RPC: '.__METHOD__.': scalar xmlrpc value can have only one value'); return 0; case 3: - error_log('XML-RPC: '.__METHOD__.': cannot add anonymous scalar to struct xmlrpcval'); + error_log('XML-RPC: '.__METHOD__.': cannot add anonymous scalar to struct xmlrpc value'); return 0; case 2: // we're adding a scalar value to an array here @@ -464,9 +464,9 @@ class Value { reset($this->me); list($a,)=each($this->me); - if($a==static::xmlrpcI4) + if($a==static::$xmlrpcI4) { - $a=static::xmlrpcInt; + $a=static::$xmlrpcInt; } return $a; }