From 58f5417d8f0d40e143c06d6bd5b2ceeef79c9c38 Mon Sep 17 00:00:00 2001 From: gggeek Date: Fri, 27 May 2022 10:18:50 +0000 Subject: [PATCH] clean up demo files --- demo/client/agesort.php | 42 ++++++++++++++++---------------- demo/client/getstatename.php | 36 ++++++++++++++------------- demo/client/introspect.php | 44 ++++++++++++++++++--------------- demo/client/mail.php | 32 +++++++++++++----------- demo/client/proxy.php | 35 +++++++++++++++++++++------ demo/client/which.php | 32 +++++++++++++----------- demo/client/wrap.php | 30 +++++++++++++---------- demo/server/discuss.php | 6 +++++ demo/server/proxy.php | 9 ++++--- demo/server/server.php | 3 ++- demo/vardemo.php | 47 +++++++++++++++++++----------------- 11 files changed, 183 insertions(+), 133 deletions(-) diff --git a/demo/client/agesort.php b/demo/client/agesort.php index 9ad397fc..6b7be6af 100644 --- a/demo/client/agesort.php +++ b/demo/client/agesort.php @@ -1,21 +1,21 @@ - + xmlrpc - Agesort demo

Agesort demo

- -

Send an array of 'name' => 'age' pairs to the server that will send it back sorted.

- +

Send an array of "name" => "age" pairs to the server that will send it back sorted.

The source code demonstrates basic lib usage, including handling of xmlrpc arrays and structs

-

You can see the source to this page here: agesort.php

- 24, "Edd" => 45, "Joe" => 37, "Fred" => 27); -print "This is the input data:
";
+output("This is the input data:
");
 foreach ($inAr as $key => $val) {
-    print $key . ", " . $val . "\n";
+    output($key . ", " . $val . "\n");
 }
-print "
"; +output("
"); // Create parameters from the input array: an xmlrpc array of xmlrpc structs $p = array(); @@ -29,7 +29,7 @@ foreach ($inAr as $key => $val) { ); } $v = new PhpXmlRpc\Value($p, "array"); -print "Encoded into xmlrpc format it looks like this:
\n" . htmlentities($v->serialize()) . "
\n"; +output("Encoded into xmlrpc format it looks like this:
\n" . htmlentities($v->serialize()) . "
\n"); // create client and message objects $req = new PhpXmlRpc\Request('examples.sortByAge', array($v)); @@ -39,27 +39,27 @@ $client = new PhpXmlRpc\Client(XMLRPCSERVER); $client->setDebug(2); // send request -print "Now sending request (detailed debug info follows)"; +output("Now sending request (detailed debug info follows)"); $resp = $client->send($req); // check response for errors, and take appropriate action if (!$resp->faultCode()) { - print "The server gave me these results:
";
+    output("The server gave me these results:
");
     $value = $resp->value();
     foreach ($value as $struct) {
         $name = $struct["name"];
         $age = $struct["age"];
-        print htmlspecialchars($name->scalarval()) . ", " . htmlspecialchars($age->scalarval()) . "\n";
+        output(htmlspecialchars($name->scalarval()) . ", " . htmlspecialchars($age->scalarval()) . "\n");
     }
 
-    print "
For nerds: I got this value back
" .
-        htmlentities($resp->serialize()) . "

\n"; + output("
For nerds: I got this value back
" .
+        htmlentities($resp->serialize()) . "

\n"); } else { - print "An error occurred:
";
-    print "Code: " . htmlspecialchars($resp->faultCode()) .
-        "\nReason: '" . htmlspecialchars($resp->faultString()) . '\'

'; + output("An error occurred:
");
+    output("Code: " . htmlspecialchars($resp->faultCode()) .
+        "\nReason: '" . htmlspecialchars($resp->faultString()) . '\'

'); } -?> - - +output("\n"); + +require_once __DIR__ . "/_append.php"; diff --git a/demo/client/getstatename.php b/demo/client/getstatename.php index a83d9079..89b56cd7 100644 --- a/demo/client/getstatename.php +++ b/demo/client/getstatename.php @@ -1,14 +1,14 @@ - + xmlrpc - Getstatename demo

Getstatename demo

-

Send a U.S. state number to the server and get back the state name

-

The code demonstrates usage of automatic encoding/decoding of php variables into xmlrpc values

-

You can see the source to this page here: getstatename.php

-encode($stateNo)) ); - print "Sending the following request:
\n\n" . htmlentities($req->serialize()) . "\n\n
Debug info of server data follows...\n\n"; + output("Sending the following request:
\n\n" . htmlentities($req->serialize()) . "\n\n
Debug info of server data follows...\n\n"); $client = new PhpXmlRpc\Client(XMLRPCSERVER); $client->setDebug(1); $r = $client->send($req); if (!$r->faultCode()) { $v = $r->value(); - print "
State number " . $stateNo . " is " - . htmlspecialchars($encoder->decode($v)) . "

"; + output("
State number " . $stateNo . " is " + . htmlspecialchars($encoder->decode($v)) . "

"); } else { - print "An error occurred: "; - print "Code: " . htmlspecialchars($r->faultCode()) - . " Reason: '" . htmlspecialchars($r->faultString()) . "'

"; + output("An error occurred: "); + output("Code: " . htmlspecialchars($r->faultCode()) + . " Reason: '" . htmlspecialchars($r->faultString()) . "'

"); } } else { $stateNo = ""; } -print "
-
-

Enter a state number to query its name

"; +output("
+ + +
+

Enter a state number to query its name

"); + +output("\n"); -?> - - +require_once __DIR__ . "/_append.php"; diff --git a/demo/client/introspect.php b/demo/client/introspect.php index f8bb6b0f..1c74ee69 100644 --- a/demo/client/introspect.php +++ b/demo/client/introspect.php @@ -1,23 +1,26 @@ - + xmlrpc - Introspect demo

Introspect demo

Query server for available methods and their description

The code demonstrates usage of multicall and introspection methods

You can see the source to this page here: introspect.php

-faultCode() - . " Reason: '" . $r->faultString() . "'
"; + output("An error occurred: "); + output("Code: " . $r->faultCode() . " Reason: '" . $r->faultString() . "'
"); } $client = new PhpXmlRpc\Client(XMLRPCSERVER); // First off, let's retrieve the list of methods available on the remote server -print "

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

\n"; +output("

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

\n"); $req = new PhpXmlRpc\Request('system.listMethods'); $resp = $client->send($req); @@ -28,7 +31,7 @@ if ($resp->faultCode()) { // Then, retrieve the signature and help text of each available method foreach ($v as $methodName) { - print "

" . $methodName->scalarval() . "

\n"; + output("

" . $methodName->scalarval() . "

\n"); // build messages first, add params later $m1 = new PhpXmlRpc\Request('system.methodHelp'); $m2 = new PhpXmlRpc\Request('system.methodSignature'); @@ -45,40 +48,41 @@ if ($resp->faultCode()) { $val = $rs[0]->value(); $txt = $val->scalarval(); if ($txt != "") { - print "

Documentation

${txt}

\n"; + output("

Documentation

${txt}

\n"); } else { - print "

No documentation available.

\n"; + output("

No documentation available.

\n"); } } if ($rs[1]->faultCode()) { display_error($rs[1]); } else { - print "

Signature

\n"; + output("

Signature

\n"); // note: using PhpXmlRpc\Encoder::decode() here would lead to cleaner code $val = $rs[1]->value(); if ($val->kindOf() == "array") { foreach ($val as $x) { $ret = $x[0]; - print "" . htmlspecialchars($ret->scalarval()) . " " - . htmlspecialchars($methodName->scalarval()) . "("; + output("" . htmlspecialchars($ret->scalarval()) . " " + . htmlspecialchars($methodName->scalarval()) . "("); if ($x->count() > 1) { for ($k = 1; $k < $x->count(); $k++) { $y = $x[$k]; - print htmlspecialchars($y->scalarval()); + output(htmlspecialchars($y->scalarval())); if ($k < $x->count() - 1) { - print ", "; + output(", "); } } } - print ")
\n"; + output(")

\n"); } } else { - print "Signature unknown\n"; + output("Signature unknown\n"); } - print "

\n"; + output("

\n"); } } } -?> - - + +output("\n"); + +require_once __DIR__ . "/_append.php"; diff --git a/demo/client/mail.php b/demo/client/mail.php index 4907a7a7..cd726b54 100644 --- a/demo/client/mail.php +++ b/demo/client/mail.php @@ -1,17 +1,18 @@ - + xmlrpc - Mail demo

Mail demo

-

This form enables you to send mail via an XML-RPC server. When you press Send this page will reload, showing you the XML-RPC request sent to the host server, the XML-RPC response received and the internal evaluation done by the PHP implementation.

-

You can see the source to this page here: mail.php
And the source to a functionally identical mail-by-XML-RPC server in the file server.php included with the library (look for the 'mail_send' + href="../server/server.php?showSource=1">server.php included with the library (look for the "mail_send" method)

-setDebug(2); $resp = $client->send($req); if (!$resp->faultCode()) { - print "Mail sent OK
\n"; + output("Mail sent OK
\n"); } else { - print ""; - print "Mail send failed
\n"; - print "Fault: "; - print "Code: " . htmlspecialchars($resp->faultCode()) . - " Reason: '" . htmlspecialchars($resp->faultString()) . "'
"; - print "

"; + output(""); + output("Mail send failed
\n"); + output("Fault: "); + output("Code: " . htmlspecialchars($resp->faultCode()) . + " Reason: '" . htmlspecialchars($resp->faultString()) . "'
"); + output("

"); } } -?> +output('
From

@@ -53,4 +54,7 @@ if (isset($_POST["mailto"]) && $_POST["mailto"]) {
- + +'); + +require_once __DIR__ . "/_append.php"; diff --git a/demo/client/proxy.php b/demo/client/proxy.php index 9b7fce6b..8e89e81e 100644 --- a/demo/client/proxy.php +++ b/demo/client/proxy.php @@ -1,20 +1,24 @@ - + xmlrpc - Proxy demo

proxy demo

-

Query server using a 'proxy' object

-

The code demonstrates usage for the terminally lazy. For a more complete proxy, look at at the Wrapper class

+

Query server using a "proxy" object

+

The code demonstrates usage for the terminally lazy. For a more complete proxy, look at the Wrapper class

You can see the source to this page here: proxy.php

-client = $client; + $this->prefix = $prefix; } /** @@ -48,12 +52,29 @@ class PhpXmlRpcProxy return $resp->value(); } } + + /** + * In case the remote method name has characters which are not valid as php method names, use this. + * + * @param string $name remote function name. Will be prefixed + * @param array $arguments + * + * @return mixed + * + * @throws Exception + */ + public function call($name, $arguments) + { + return $this->__call($name, $arguments); + } } $stateNo = rand(1, 51); $proxy = new PhpXmlRpcProxy(new PhpXmlRpc\Client(XMLRPCSERVER)); $stateName = $proxy->getStateName($stateNo); -echo "State $stateNo is ".htmlspecialchars($stateName); +output("State $stateNo is ".htmlspecialchars($stateName)); + +output("\n"); require_once __DIR__ . "/_append.php"; diff --git a/demo/client/which.php b/demo/client/which.php index 1c1ba368..23a08b33 100644 --- a/demo/client/which.php +++ b/demo/client/which.php @@ -1,11 +1,14 @@ - + xmlrpc - Which toolkit demo

Which toolkit demo

Query server for toolkit information

The code demonstrates usage of the PhpXmlRpc\Encoder class

You can see the source to this page here: which.php

-send($req); if (!$resp->faultCode()) { $encoder = new PhpXmlRpc\Encoder(); $value = $encoder->decode($resp->value()); - print "Toolkit info:
\n"; - print "
";
-    print "name: " . htmlspecialchars($value["toolkitName"]) . "\n";
-    print "version: " . htmlspecialchars($value["toolkitVersion"]) . "\n";
-    print "docs: " . htmlspecialchars($value["toolkitDocsUrl"]) . "\n";
-    print "os: " . htmlspecialchars($value["toolkitOperatingSystem"]) . "\n";
-    print "
"; + output("Toolkit info:
\n"); + output("
");
+    output("name: " . htmlspecialchars($value["toolkitName"]) . "\n");
+    output("version: " . htmlspecialchars($value["toolkitVersion"]) . "\n");
+    output("docs: " . htmlspecialchars($value["toolkitDocsUrl"]) . "\n");
+    output("os: " . htmlspecialchars($value["toolkitOperatingSystem"]) . "\n");
+    output("
"); } else { - print "An error occurred: "; - print "Code: " . htmlspecialchars($resp->faultCode()) . " Reason: '" . htmlspecialchars($resp->faultString()) . "'\n"; + output("An error occurred: "); + output("Code: " . htmlspecialchars($resp->faultCode()) . " Reason: '" . htmlspecialchars($resp->faultString()) . "'\n"); } -?> - - + +output("\n"); + +require_once __DIR__ . "/_append.php"; diff --git a/demo/client/wrap.php b/demo/client/wrap.php index 4e3db40c..d7523494 100644 --- a/demo/client/wrap.php +++ b/demo/client/wrap.php @@ -1,25 +1,28 @@ - + xmlrpc - Webservice wrappper demo

Webservice wrappper demo

Wrap methods exposed by server into php functions

-

The code demonstrates usage of some the most automagic client usage possible:
+

The code demonstrates usage of some of the most automagic client usage possible:
1) client that returns php values instead of xmlrpc value objects
2) wrapping of remote methods into php functions
See also proxy.php for an alternative take

You can see the source to this page here: wrap.php

-return_type = 'phpvals'; // let client give us back php values instead of xmlrpcvals $resp = $client->send(new PhpXmlRpc\Request('system.listMethods')); if ($resp->faultCode()) { - echo "

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

\n"; + output("

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

\n"); } else { - echo "

Server methods list retrieved, now wrapping it up...

\n\n"); flush(); if ($callable) { - echo "Now testing function for remote method to convert U.S. state number into state name"; + output("Now testing function for remote method to convert U.S. state number into state name"); $stateNum = rand(1, 51); // the 2nd parameter gets added to the closure - it is the debug level to be used for the client $stateName = $callable($stateNum, 2); - echo "State $stateNum is ".htmlspecialchars($stateName); + output("State $stateNum is ".htmlspecialchars($stateName)); } } -?> - - + +output("\n"); + +require_once __DIR__ . "/_append.php"; diff --git a/demo/server/discuss.php b/demo/server/discuss.php index ca5dd7d7..08058cd4 100644 --- a/demo/server/discuss.php +++ b/demo/server/discuss.php @@ -1,4 +1,8 @@ decode($req->getParam(0)); + // NB: here we should validate the received url, using f.e. a whitelist... $client = new PhpXmlRpc\Client($url); if ($req->getNumParams() > 3) { @@ -73,7 +74,7 @@ function forward_request($req) return $client->send($req, $timeout); } -// run the server +// Run the server // NB: take care not to output anything else after this call, as it will mess up the responses and it will be hard to // debug. In case you have to do so, at least re-emit a correct Content-Length http header (requires output buffering) $server = new PhpXmlRpc\Server( diff --git a/demo/server/server.php b/demo/server/server.php index 4ab3be54..a40a69de 100644 --- a/demo/server/server.php +++ b/demo/server/server.php @@ -4,9 +4,10 @@ * * Implements a lot of webservices, including a suite of services used for interoperability testing (validator1 methods), * and some whose only purpose is to be used for unit-testing the library. + * It also allows the caller to configure specific features by using "out of band" query string parameters. * * Please _do not_ copy this file verbatim into your production server. - **/ + */ require_once __DIR__ . "/_prepend.php"; diff --git a/demo/vardemo.php b/demo/vardemo.php index 70436ff7..0390f854 100644 --- a/demo/vardemo.php +++ b/demo/vardemo.php @@ -1,16 +1,19 @@ - + xmlrpc -Testing value serialization\n"; +output("

Testing value serialization

\n"); $v = new PhpXmlRpc\Value(23, "int"); -print "
" . htmlentities($v->serialize()) . "
"; +output("
" . htmlentities($v->serialize()) . "
"); $v = new PhpXmlRpc\Value("What are you saying? >> << &&"); -print "
" . htmlentities($v->serialize()) . "
"; +output("
" . htmlentities($v->serialize()) . "
"); $v = new PhpXmlRpc\Value( array( @@ -21,7 +24,7 @@ $v = new PhpXmlRpc\Value( "array" ); -print "
" . htmlentities($v->serialize()) . "
"; +output("
" . htmlentities($v->serialize()) . "
"); $v = new PhpXmlRpc\Value( array( @@ -49,11 +52,11 @@ $v = new PhpXmlRpc\Value( "struct" ); -print "
" . htmlentities($v->serialize()) . "
"; +output("
" . htmlentities($v->serialize()) . "
"); $w = new PhpXmlRpc\Value(array($v, new PhpXmlRpc\Value("That was the struct!")), "array"); -print "
" . htmlentities($w->serialize()) . "
"; +output("
" . htmlentities($w->serialize()) . "
"); $w = new PhpXmlRpc\Value("Mary had a little lamb, Whose fleece was white as snow, @@ -65,29 +68,29 @@ She tied it to a pylon Ten thousand volts went down its back And turned it into nylon", "base64" ); -print "
" . htmlentities($w->serialize()) . "
"; -print "
Value of base64 string is: '" . $w->scalarval() . "'
"; +output("
" . htmlentities($w->serialize()) . "
"); +output("
Value of base64 string is: '" . $w->scalarval() . "'
"); $req->method(''); $req->addParam(new PhpXmlRpc\Value("41", "int")); -print "

Testing request serialization

\n"; +output("

Testing request serialization

\n"); $op = $req->serialize(); -print "
" . htmlentities($op) . "
"; +output("
" . htmlentities($op) . "
"); -print "

Testing ISO date format

\n";
+output("

Testing ISO date format

\n");
 
 $t = time();
 $date = PhpXmlRpc\Helper\Date::iso8601Encode($t);
-print "Now is $t --> $date\n";
-print "Or in UTC, that is " . PhpXmlRpc\Helper\Date::iso8601Encode($t, 1) . "\n";
+output("Now is $t --> $date\n");
+output("Or in UTC, that is " . PhpXmlRpc\Helper\Date::iso8601Encode($t, 1) . "\n");
 $tb = PhpXmlRpc\Helper\Date::iso8601Decode($date);
-print "That is to say $date --> $tb\n";
-print "Which comes out at " . PhpXmlRpc\Helper\Date::iso8601Encode($tb) . "\n";
-print "Which was the time in UTC at " . PhpXmlRpc\Helper\Date::iso8601Encode($tb, 1) . "\n";
+output("That is to say $date --> $tb\n");
+output("Which comes out at " . PhpXmlRpc\Helper\Date::iso8601Encode($tb) . "\n");
+output("Which was the time in UTC at " . PhpXmlRpc\Helper\Date::iso8601Encode($tb, 1) . "\n");
+
+output("
\n"); -print "
\n"; +output(''); -?> - - +require_once __DIR__ . "/client/_append.php"; -- 2.47.0