From 24898d86a8cbbcc0696f2c02fecfe88f4f61d512 Mon Sep 17 00:00:00 2001 From: gggeek Date: Mon, 30 Jan 2023 16:46:59 +0000 Subject: [PATCH] update demos to use setOption/getOption --- demo/client/getstatename.php | 2 +- demo/client/introspect.php | 4 ++-- demo/client/loggerinjection.php | 2 +- demo/client/parallel.php | 4 ++-- demo/client/proxy.php | 7 ++++--- demo/client/which.php | 2 +- demo/client/windowscharset.php | 8 ++++---- demo/client/wrap.php | 2 +- demo/server/codegen.php | 4 ++-- demo/server/discuss.php | 2 +- demo/server/server.php | 6 +++--- 11 files changed, 22 insertions(+), 21 deletions(-) diff --git a/demo/client/getstatename.php b/demo/client/getstatename.php index dfcef9ff..b69cb774 100644 --- a/demo/client/getstatename.php +++ b/demo/client/getstatename.php @@ -26,7 +26,7 @@ if (isset($_POST['stateno']) && $_POST['stateno'] != "") { output("Sending the following request:
\n\n" . htmlentities($req->serialize()) .
         "\n\n
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(); diff --git a/demo/client/introspect.php b/demo/client/introspect.php index b0919806..8349dd19 100644 --- a/demo/client/introspect.php +++ b/demo/client/introspect.php @@ -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("

methods available at http://" . $client->server . $client->path . "

\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) { diff --git a/demo/client/loggerinjection.php b/demo/client/loggerinjection.php index 2791922d..28331f78 100644 --- a/demo/client/loggerinjection.php +++ b/demo/client/loggerinjection.php @@ -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...
"); diff --git a/demo/client/parallel.php b/demo/client/parallel.php index be3f4fcd..d21c18d1 100644 --- a/demo/client/parallel.php +++ b/demo/client/parallel.php @@ -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; diff --git a/demo/client/proxy.php b/demo/client/proxy.php index 35b70584..789dce8c 100644 --- a/demo/client/proxy.php +++ b/demo/client/proxy.php @@ -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 diff --git a/demo/client/which.php b/demo/client/which.php index 21f06e7b..7a303b13 100644 --- a/demo/client/which.php +++ b/demo/client/which.php @@ -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); diff --git a/demo/client/windowscharset.php b/demo/client/windowscharset.php index 32af320d..c2c425be 100644 --- a/demo/client/windowscharset.php +++ b/demo/client/windowscharset.php @@ -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(); diff --git a/demo/client/wrap.php b/demo/client/wrap.php index beb271d1..92200a05 100644 --- a/demo/client/wrap.php +++ b/demo/client/wrap.php @@ -17,7 +17,7 @@ output(' '); $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("

Server methods list could not be retrieved: error {$resp->faultCode()} '" . htmlspecialchars($resp->faultString()) . "'

\n"); diff --git a/demo/server/codegen.php b/demo/server/codegen.php index c76d3015..08259266 100644 --- a/demo/server/codegen.php +++ b/demo/server/codegen.php @@ -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'); diff --git a/demo/server/discuss.php b/demo/server/discuss.php index b6bb3af7..20a4ff63 100644 --- a/demo/server/discuss.php +++ b/demo/server/discuss.php @@ -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... diff --git a/demo/server/server.php b/demo/server/server.php index 7ff956bd..333ec45e 100644 --- a/demo/server/server.php +++ b/demo/server/server.php @@ -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. -- 2.47.0