update demos to use setOption/getOption
authorgggeek <giunta.gaetano@gmail.com>
Mon, 30 Jan 2023 16:46:59 +0000 (16:46 +0000)
committergggeek <giunta.gaetano@gmail.com>
Mon, 30 Jan 2023 16:46:59 +0000 (16:46 +0000)
demo/client/getstatename.php
demo/client/introspect.php
demo/client/loggerinjection.php
demo/client/parallel.php
demo/client/proxy.php
demo/client/which.php
demo/client/windowscharset.php
demo/client/wrap.php
demo/server/codegen.php
demo/server/discuss.php
demo/server/server.php

index dfcef9f..b69cb77 100644 (file)
@@ -26,7 +26,7 @@ if (isset($_POST['stateno']) && $_POST['stateno'] != "") {
     output("Sending the following request:<pre>\n\n" . htmlentities($req->serialize()) .
         "\n\n</pre>Debug info of server data follows...\n\n");
     $client = new Client(XMLRPCSERVER);
-    $client->setDebug(1);
+    $client->setOption(Client::OPT_DEBUG, 1);
     $resp = $client->send($req);
     if (!$resp->faultCode()) {
         $val = $resp->value();
index b091980..8349dd1 100644 (file)
@@ -22,7 +22,7 @@ function display_error($r)
 
 $client = new Client(XMLRPCSERVER);
 // tell the client we want back plain php values
-$client->return_type = XMLRPCParser::RETURN_PHP;
+$client->setOption(Client::OPT_RETURN_TYPE, XMLRPCParser::RETURN_PHP);
 
 // First off, let's retrieve the list of methods available on the remote server
 output("<h3>methods available at http://" . $client->server . $client->path . "</h3>\n");
@@ -43,7 +43,7 @@ if ($resp->faultCode()) {
         }
     }
 
-    $client->no_multicall = $avoidMulticall;
+    $client->setOption(Client::OPT_NO_MULTICALL, $avoidMulticall);
 
     // Then, retrieve the signature and help text of each available method
     foreach ($v as $methodName) {
index 2791922..28331f7 100644 (file)
@@ -64,7 +64,7 @@ $client = new Client(XMLRPCSERVER);
 $client->setDebug(2);
 
 // avid compressed responses, as they mess up the output if echoed on the command-line
-$client->setAcceptedCompression('');
+$client->setOption(Client::OPT_ACCEPTED_COMPRESSION, '');
 
 // send request
 output("Sending the request. No output debug should appear below...<br>");
index be3f4fc..d21c18d 100644 (file)
@@ -106,7 +106,7 @@ for ($i = 0; $i < $num_tests; $i++) {
 }
 
 $client = new ParallelClient(XMLRPCSERVER);
-$client->no_multicall = true;
+$client->setOption(Client::OPT_NO_MULTICALL,  true);
 
 // a minimal benchmark - use 3 strategies to execute the same 25 calls: sequentially, using parallel http requests, and
 // using a single system.multiCall request
@@ -126,7 +126,7 @@ $t = microtime(true) - $t;
 echo "Parallel send: " . sprintf('%.3f', $t) . " secs.\n";
 flush();
 
-$client->no_multicall = false;
+$client->setOption(Client::OPT_NO_MULTICALL, false);
 $t = microtime(true);
 $resp = $client->send($reqs);
 $t = microtime(true) - $t;
index 35b7058..789dce8 100644 (file)
@@ -50,12 +50,12 @@ class XmlRpcProxy
         }
 
         // just in case this was set to something else
-        $originalReturnType = $this->client->return_type;
-        $this->client->return_type = 'phpvals';
+        $originalReturnType = $this->client->getOption(\PhpXmlRpc\Client::OPT_RETURN_TYPE);
+        $this->client->setOption(\PhpXmlRpc\Client::OPT_RETURN_TYPE, 'phpvals');
 
         $resp = $this->client->send(new PhpXmlRpc\Request($this->prefix.$name, $args));
 
-        $this->client->return_type = $originalReturnType;
+        $this->client->setOption(\PhpXmlRpc\Client::OPT_RETURN_TYPE, $originalReturnType);
 
         if ($resp->faultCode()) {
             throw new \Exception($resp->faultString(), $resp->faultCode());
@@ -66,6 +66,7 @@ class XmlRpcProxy
 
     /**
      * In case the remote method name has characters which are not valid as php method names, use this.
+     * (note that, in theory this is unlikely, as php has a broader definition for identifiers than xml-rpc method names)
      *
      * @param string $name remote function name. Will be prefixed
      * @param array $arguments any php value will do. For xml-rpc base64 values, wrap them in a Value object
index 21f06e7..7a303b1 100644 (file)
@@ -31,7 +31,7 @@ $client->setCurlOptions(array(CURLOPT_FOLLOWLOCATION => true, CURLOPT_POSTREDIR
 $client->setRequestCompression('gzip');
 
 // ask the client to give us back xml
-$client->return_type = 'xml';
+$client->setOption(Client::OPT_RETURN_TYPE, 'xml');
 
 $client->setDebug(1);
 
index 32af320..c2c425b 100644 (file)
@@ -32,13 +32,13 @@ var_dump($input);
 $c = new Client(XMLRPCSERVER);
 
 // allow the full request and response to be seen on screen
-$c->setDebug(2);
+$c->setOption(Client::OPT_DEBUG, 2);
 // tell the server not to compress the response - this is not necessary btw, it is only done to make the debug look nicer
-$c->accepted_compression = array();
+$c->setOption(Client::OPT_ACCEPTED_COMPRESSION, array());
 // tell the server not to encode everything as ASCII - this is not necessary btw, it is only done to make the debug look nicer
-$c->accepted_charset_encodings = array('UTF-8');
+$c->setOption(Client::OPT_ACCEPTED_CHARSET_ENCODINGS, array('UTF-8'));
 // force the client not to encode everything as ASCII - this is not necessary btw, it is only done to make the debug nicer
-$c->request_charset_encoding = 'UTF-8';
+$c->setOption(Client::OPT_REQUEST_CHARSET_ENCODING, 'UTF-8');
 
 $r = $c->send(new Request('examples.stringecho', array(new Value($input))));
 $output = $r->value()->scalarval();
index beb271d..92200a0 100644 (file)
@@ -17,7 +17,7 @@ output('<html lang="en">
 ');
 
 $client = new PhpXmlRpc\Client(XMLRPCSERVER);
-$client->return_type = 'phpvals'; // let client give us back php values instead of xmlrpcvals
+$client->setOption(\PhpXmlRpc\Client::OPT_RETURN_TYPE, 'phpvals'); // let client give us back php values instead of xmlrpcvals
 $resp = $client->send(new PhpXmlRpc\Request('system.listMethods'));
 if ($resp->faultCode()) {
     output("<p>Server methods list could not be retrieved: error {$resp->faultCode()} '" . htmlspecialchars($resp->faultString()) . "'</p>\n");
index c76d301..0825926 100644 (file)
@@ -64,8 +64,8 @@ file_put_contents($targetControllerFile,
     "\$dm = require_once '$targetDispatchMapFile';\n" .
     '$s = new \PhpXmlRpc\Server($dm, false);' . "\n" .
     '// NB: do not leave these 2 debug lines enabled on publicly accessible servers!' . "\n" .
-    '$s->setDebug(2);' . "\n" .
-    '$s->exception_handling = 1;' . "\n" .
+    '$s->setOption(\PhpXmlRpc\Server::OPT_DEBUG, 2);' . "\n" .
+    '$s->setOption(\PhpXmlRpc\Server::OPT_EXCEPTION_HANDLING, 1);' . "\n" .
     '$s->service();' . "\n"
 ) || die('uh oh');
 
index b6bb3af..20a4ff6 100644 (file)
@@ -43,7 +43,7 @@ $srv->setDispatchMap(array(
 ));
 
 // let the xml-rpc server know that the method-handler functions expect plain php values
-$srv->functions_parameters_type = 'phpvals';
+$srv->setOption(Server::OPT_FUNCTIONS_PARAMETERS_TYPE, 'phpvals');
 
 // let code exceptions float all the way to the remote caller as xml-rpc faults - it helps debugging.
 // At the same time, it opens a wide security hole, and should never be enabled on public or production servers...
index 7ff956b..333ec45 100644 (file)
@@ -56,19 +56,19 @@ if (defined('TESTMODE')) {
 PhpXmlRpc::$xmlrpc_null_extension = true;
 
 $s = new Server($signatures, false);
-$s->setDebug(3);
+$s->setOption(Server::OPT_DEBUG, 3);
 
 // Out-of-band information: let the client manipulate the server operations.
 // We do this to help the testsuite script: *** do not reproduce in production or public environments! ***
 if (defined('TESTMODE')) {
     if (isset($_GET['RESPONSE_ENCODING'])) {
-        $s->response_charset_encoding = $_GET['RESPONSE_ENCODING'];
+        $s->setOption(Server::OPT_RESPONSE_CHARSET_ENCODING, $_GET['RESPONSE_ENCODING']);
     }
     if (isset($_GET['DETECT_ENCODINGS'])) {
         PhpXmlRpc::$xmlrpc_detectencodings = $_GET['DETECT_ENCODINGS'];
     }
     if (isset($_GET['EXCEPTION_HANDLING'])) {
-        $s->exception_handling = $_GET['EXCEPTION_HANDLING'];
+        $s->setOption(Server::OPT_EXCEPTION_HANDLING, $_GET['EXCEPTION_HANDLING']);
     }
     if (isset($_GET['FORCE_AUTH'])) {
         // We implement both  Basic and Digest auth in php to avoid having to set it up in a vhost.