From 3f49519b2d8157ac9da42bcf5836bf94020de485 Mon Sep 17 00:00:00 2001 From: gggeek Date: Sun, 22 Mar 2015 18:53:09 +0000 Subject: [PATCH] Start clean up of demo code: use new API, camelCase variables, readable variables, usage of autoloader, simpler client constructor --- demo/client/agesort.php | 48 ++++++++++++---------- demo/client/client.php | 34 ++++++++------- demo/client/comment.php | 41 ++++++++++--------- demo/client/introspect.php | 29 +++++++------ demo/client/mail.php | 52 +++++++++++------------ demo/client/simple_call.php | 10 +++-- demo/client/which.php | 30 ++++++++------ demo/client/wrap.php | 46 +++++++++++---------- demo/client/zopetest.php | 28 +++++++------ demo/server/discuss.php | 10 ++--- demo/server/proxy.php | 8 ++-- demo/server/server.php | 82 ++++++++++++++++++------------------- demo/vardemo.php | 46 ++++++++++----------- 13 files changed, 239 insertions(+), 225 deletions(-) diff --git a/demo/client/agesort.php b/demo/client/agesort.php index 6e00de0..7f870c6 100644 --- a/demo/client/agesort.php +++ b/demo/client/agesort.php @@ -1,5 +1,5 @@ -xmlrpc +xmlrpc - Agesort demo

Agesort demo

@@ -9,12 +9,13 @@

24, "Edd" => 45, "Joe" => 37, "Fred" => 27); -reset($inAr); print "This is the input data:
";
-while (list($key, $val) = each($inAr)) {
+foreach($inAr as $key => $val) {
     print $key . ", " . $val . "\n";
 }
 print "
"; @@ -22,41 +23,46 @@ print ""; // create parameters from the input array: an xmlrpc array of xmlrpc structs $p = array(); foreach ($inAr as $key => $val) { - $p[] = new xmlrpcval(array("name" => new xmlrpcval($key), - "age" => new xmlrpcval($val, "int")), "struct"); + $p[] = new PhpXmlRpc\Value( + array( + "name" => new PhpXmlRpc\Value($key), + "age" => new PhpXmlRpc\Value($val, "int") + ), + "struct" + ); } -$v = new xmlrpcval($p, "array"); +$v = new PhpXmlRpc\Value($p, "array"); print "Encoded into xmlrpc format it looks like this:
\n" . htmlentities($v->serialize()) . "
\n"; // create client and message objects -$f = new xmlrpcmsg('examples.sortByAge', array($v)); -$c = new xmlrpc_client("/server.php", "phpxmlrpc.sourceforge.net", 80); +$req = new PhpXmlRpc\Request('examples.sortByAge', array($v)); +$client = new PhpXmlRpc\Client("http://phpxmlrpc.sourceforge.net/server.php"); // set maximum debug level, to have the complete communication printed to screen -$c->setDebug(2); +$client->setDebug(2); // send request print "Now sending request (detailed debug info follows)"; -$r = &$c->send($f); +$resp = $client->send($req); // check response for errors, and take appropriate action -if (!$r->faultCode()) { +if (!$resp->faultCode()) { print "The server gave me these results:
";
-    $v = $r->value();
-    $max = $v->arraysize();
+    $value = $resp->value();
+    $max = $value->arraysize();
     for ($i = 0; $i < $max; $i++) {
-        $rec = $v->arraymem($i);
-        $n = $rec->structmem("name");
-        $a = $rec->structmem("age");
-        print htmlspecialchars($n->scalarval()) . ", " . htmlspecialchars($a->scalarval()) . "\n";
+        $struct = $value->arraymem($i);
+        $name = $struct->structmem("name");
+        $age = $struct->structmem("age");
+        print htmlspecialchars($name->scalarval()) . ", " . htmlspecialchars($age->scalarval()) . "\n";
     }
 
     print "
For nerds: I got this value back
" .
-        htmlentities($r->serialize()) . "

\n"; + htmlentities($resp->serialize()) . "

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

'; + print "Code: " . htmlspecialchars($resp->faultCode()) . + "\nReason: '" . htmlspecialchars($resp->faultString()) . '\'
'; } ?> diff --git a/demo/client/client.php b/demo/client/client.php index 755729d..06a256a 100644 --- a/demo/client/client.php +++ b/demo/client/client.php @@ -1,5 +1,5 @@ -xmlrpc +xmlrpc - Getstatename demo

Getstatename demo

@@ -7,26 +7,24 @@

The code demonstrates usage of the php_xmlrpc_encode function

encode($stateNo)) ); - print "
Sending the following request:\n\n" . htmlentities($f->serialize()) . "\n\nDebug info of server data follows...\n\n";
-    $c = new xmlrpc_client("/server.php", "phpxmlrpc.sourceforge.net", 80);
-    $c->setDebug(1);
-    $r = &$c->send($f);
+    print "Sending the following request:
\n\n" . htmlentities($req->serialize()) . "\n\n
Debug info of server data follows...\n\n"; + $client = new PhpXmlRpc\Client("http://phpxmlrpc.sourceforge.net/server.php"); + $client->setDebug(1); + $r = $client->send($req); if (!$r->faultCode()) { $v = $r->value(); - print "

State number " . $stateno . " is " - . htmlspecialchars($v->scalarval()) . "
"; + print "
State number " . $stateNo . " is " + . htmlspecialchars($v->scalarval()) . "
"; // print "
I got this value back
" .
         //  htmlentities($r->serialize()). "

\n"; } else { @@ -35,11 +33,11 @@ if (isset($HTTP_POST_VARS["stateno"]) && $HTTP_POST_VARS["stateno"] != "") { . " Reason: '" . htmlspecialchars($r->faultString()) . "'
"; } } else { - $stateno = ""; + $stateNo = ""; } print "
-
+

Enter a state number to query its name

"; ?> diff --git a/demo/client/comment.php b/demo/client/comment.php index e457836..2c34d3f 100644 --- a/demo/client/comment.php +++ b/demo/client/comment.php @@ -1,7 +1,9 @@ send($msg); + $req = new PhpXmlRpc\Request($method, $args); + $resp = $client->send($req); if (!$resp) { print "

IO error: " . $client->errstr . "

"; bomb(); @@ -24,12 +26,12 @@ function dispatch($client, $method, $args) bomb(); } - return php_xmlrpc_decode($resp->value()); + $encoder = new PhpXmlRpc\Encoder(); + return $encoder->decode($resp->value()); } // create client for discussion server -$dclient = new xmlrpc_client("${mydir}/discuss.php", - "xmlrpc.usefulinc.com", 80); +$dclient = new PhpXmlRpc\Client("http://xmlrpc.usefulinc.com/${mydir}discuss.php"); // check if we're posting a comment, and send it if so @$storyid = $_POST["storyid"]; @@ -38,9 +40,9 @@ if ($storyid) { // print "Returning to " . $HTTP_POST_VARS["returnto"]; $res = dispatch($dclient, "discuss.addComment", - array(new xmlrpcval($storyid), - new xmlrpcval(stripslashes(@$_POST["name"])), - new xmlrpcval(stripslashes(@$_POST["commenttext"])),)); + array(new PhpXmlRpc\Value($storyid), + new PhpXmlRpc\Value(stripslashes(@$_POST["name"])), + new PhpXmlRpc\Value(stripslashes(@$_POST["commenttext"])),)); // send the browser back to the originating page Header("Location: ${mydir}/comment.php?catid=" . @@ -65,8 +67,7 @@ if (@$_GET["oc"] == $catid) { $chanid = 0; } -$client = new xmlrpc_client("/meerkat/xml-rpc/server.php", - "www.oreillynet.com", 80); +$client = new PhpXmlRpc\Client("http://www.oreillynet.com/meerkat/xml-rpc/server.php"); if (@$_GET["comment"] && (!@$_GET["cdone"]) @@ -98,17 +99,17 @@ if (@$_GET["comment"] && $categories = dispatch($client, "meerkat.getCategories", array()); if ($catid) { $sources = dispatch($client, "meerkat.getChannelsByCategory", - array(new xmlrpcval($catid, "int"))); + array(new PhpXmlRpc\Value($catid, "int"))); } if ($chanid) { $stories = dispatch($client, "meerkat.getItems", - array(new xmlrpcval( + array(new PhpXmlRpc\Value( array( - "channel" => new xmlrpcval($chanid, "int"), - "ids" => new xmlrpcval(1, "int"), - "descriptions" => new xmlrpcval(200, "int"), - "num_items" => new xmlrpcval(5, "int"), - "dates" => new xmlrpcval(0, "int"), + "channel" => new PhpXmlRpc\Value($chanid, "int"), + "ids" => new PhpXmlRpc\Value(1, "int"), + "descriptions" => new PhpXmlRpc\Value(200, "int"), + "num_items" => new PhpXmlRpc\Value(5, "int"), + "dates" => new PhpXmlRpc\Value(0, "int"), ), "struct"))); } ?> @@ -178,7 +179,7 @@ if (@$_GET["comment"] && print "\n"; // now look for existing comments $res = dispatch($dclient, "discuss.getComments", - array(new xmlrpcval($v['id']))); + array(new PhpXmlRpc\Value($v['id']))); if (sizeof($res) > 0) { print "

" . "Comments on this story:

"; diff --git a/demo/client/introspect.php b/demo/client/introspect.php index cd08423..7200604 100644 --- a/demo/client/introspect.php +++ b/demo/client/introspect.php @@ -1,11 +1,14 @@ -xmlrpc +xmlrpc - Introspect demo

Introspect demo

Query server for available methods and their description

The code demonstrates usage of multicall and introspection methods

faultString() . "'
"; } // 'new style' client constructor -$c = new xmlrpc_client("http://phpxmlrpc.sourceforge.net/server.php"); -print "

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

\n"; -$m = new xmlrpcmsg('system.listMethods'); -$r = &$c->send($m); -if ($r->faultCode()) { - display_error($r); +$client = new PhpXmlRpc\Client("http://phpxmlrpc.sourceforge.net/server.php"); +print "

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

\n"; +$req = new PhpXmlRpc\Request('system.listMethods'); +$resp = $client->send($req); +if ($resp->faultCode()) { + display_error($resp); } else { - $v = $r->value(); + $v = $resp->value(); for ($i = 0; $i < $v->arraysize(); $i++) { $mname = $v->arraymem($i); print "

" . $mname->scalarval() . "

\n"; // build messages first, add params later - $m1 = new xmlrpcmsg('system.methodHelp'); - $m2 = new xmlrpcmsg('system.methodSignature'); - $val = new xmlrpcval($mname->scalarval(), "string"); + $m1 = new PhpXmlRpc\Request('system.methodHelp'); + $m2 = new PhpXmlRpc\Request('system.methodSignature'); + $val = new PhpXmlRpc\Value($mname->scalarval(), "string"); $m1->addParam($val); $m2->addParam($val); // send multiple messages in one pass. // If server does not support multicall, client will fall back to 2 separate calls $ms = array($m1, $m2); - $rs = &$c->send($ms); + $rs = $client->send($ms); if ($rs[0]->faultCode()) { display_error($rs[0]); } else { diff --git a/demo/client/mail.php b/demo/client/mail.php index 6b6abd4..e1966b3 100644 --- a/demo/client/mail.php +++ b/demo/client/mail.php @@ -1,14 +1,12 @@ -xmlrpc +xmlrpc - Mail demo

Mail demo

@@ -23,41 +21,37 @@ if ((isset($HTTP_GET_VARS['showSource']) && $HTTP_GET_VARS['showSource']) || href="../server/server.php?showSource=1">server.php included with the library (look for the 'mail_send' method)

addParam(new xmlrpcval($HTTP_POST_VARS["mailto"])); - $f->addParam(new xmlrpcval($HTTP_POST_VARS["mailsub"])); - $f->addParam(new xmlrpcval($HTTP_POST_VARS["mailmsg"])); - $f->addParam(new xmlrpcval($HTTP_POST_VARS["mailfrom"])); - $f->addParam(new xmlrpcval($HTTP_POST_VARS["mailcc"])); - $f->addParam(new xmlrpcval($HTTP_POST_VARS["mailbcc"])); - $f->addParam(new xmlrpcval("text/plain")); + $req = new PhpXmlRpc\Request('mail.send', array( + new PhpXmlRpc\Value($_POST["mailto"]), + new PhpXmlRpc\Value($_POST["mailsub"]), + new PhpXmlRpc\Value($_POST["mailmsg"]), + new PhpXmlRpc\Value($_POST["mailfrom"]), + new PhpXmlRpc\Value($_POST["mailcc"]), + new PhpXmlRpc\Value($_POST["mailbcc"]), + new PhpXmlRpc\Value("text/plain") + )); - $c = new xmlrpc_client($XP, $XS, 80); - $c->setDebug(2); - $r = &$c->send($f); - if (!$r->faultCode()) { + $client = new PhpXmlRpc\Client($server); + $client->setDebug(2); + $resp = $client->send($req); + if (!$resp->faultCode()) { print "Mail sent OK
\n"; } else { print ""; print "Mail send failed
\n"; print "Fault: "; - print "Code: " . htmlspecialchars($r->faultCode()) . - " Reason: '" . htmlspecialchars($r->faultString()) . "'
"; + print "Code: " . htmlspecialchars($resp->faultCode()) . + " Reason: '" . htmlspecialchars($resp->faultString()) . "'
"; print "
"; } } diff --git a/demo/client/simple_call.php b/demo/client/simple_call.php index f2c03e0..4e904be 100644 --- a/demo/client/simple_call.php +++ b/demo/client/simple_call.php @@ -6,6 +6,9 @@ * @license code licensed under the BSD License: see file license.txt */ +include_once __DIR__ . "/../../src/Autoloader.php"; +PhpXmlRpc\Autoloader::register(); + /** * Takes a client object, a remote method name, and a variable numbers of * php values, and calls the method with the supplied parameters. The @@ -43,11 +46,12 @@ function xmlrpccall_simple() return false; } - $xmlrpcval_array = array(); + $valueArray = array(); + $encoder = new PhpXmlRpc\Encoder(); foreach ($varargs as $parameter) { - $xmlrpcval_array[] = php_xmlrpc_encode($parameter); + $valueArray[] = $encoder->encode($parameter); } - return $client->send(new xmlrpcmsg($remote_function_name, $xmlrpcval_array)); + return $client->send(new PhpXmlRpc\Request($remote_function_name, $valueArray)); } } diff --git a/demo/client/which.php b/demo/client/which.php index f6ef45d..5d33215 100644 --- a/demo/client/which.php +++ b/demo/client/which.php @@ -1,25 +1,29 @@ -xmlrpc +xmlrpc - Which toolkit demo

Which toolkit demo

Query server for toolkit information

-

The code demonstrates usage of the php_xmlrpc_decode function

+

The code demonstrates usage of the PhpXmlRpc\Encoder class

send($f); -if (!$r->faultCode()) { - $v = php_xmlrpc_decode($r->value()); + +include_once __DIR__ . "/../../src/Autoloader.php"; +PhpXmlRpc\Autoloader::register(); + +$req = new PhpXmlRpc\Request('interopEchoTests.whichToolkit', array()); +$client = new PhpXmlRpc\Client("http://phpxmlrpc.sourceforge.net/server.php"); +$resp = $client->send($req); +if (!$resp->faultCode()) { + $encoder = new PhpXmlRpc\Encoder(); + $value = $encoder->decode($resp->value()); print "
";
-    print "name: " . htmlspecialchars($v["toolkitName"]) . "\n";
-    print "version: " . htmlspecialchars($v["toolkitVersion"]) . "\n";
-    print "docs: " . htmlspecialchars($v["toolkitDocsUrl"]) . "\n";
-    print "os: " . htmlspecialchars($v["toolkitOperatingSystem"]) . "\n";
+    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 "
"; } else { print "An error occurred: "; - print "Code: " . htmlspecialchars($r->faultCode()) . " Reason: '" . htmlspecialchars($r->faultString()) . "'\n"; + print "Code: " . htmlspecialchars($resp->faultCode()) . " Reason: '" . htmlspecialchars($resp->faultString()) . "'\n"; } ?> diff --git a/demo/client/wrap.php b/demo/client/wrap.php index 27a9794..13ffabb 100644 --- a/demo/client/wrap.php +++ b/demo/client/wrap.php @@ -1,48 +1,50 @@ -xmlrpc +xmlrpc - Webservice wrappper demo

Webservice wrappper demo

Wrap methods exposed by server into php functions

The code demonstrates usage of the most automagic client usage possible:
- 1) client that returns php values instead of xmlrpcval objects
+ 1) client that returns php values instead of xmlrpc value objects
2) wrapping of remote methods into php functions

return_type = 'phpvals'; // let client give us back php values instead of xmlrpcvals -$r = &$c->send(new xmlrpcmsg('system.listMethods')); -if ($r->faultCode()) { +include_once __DIR__ . "/../../src/Autoloader.php"; +PhpXmlRpc\Autoloader::register(); + +$client = new PhpXmlRpc\Client("http://phpxmlrpc.sourceforge.net/server.php"); +$client->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 '" . htmlspecialchars($r->faultString()) . "'

\n"; } else { - $testcase = ''; + $testCase = ''; + $wrapper = new PhpXmlRpc\Wrapper(); echo "

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

\n\n"; - if ($testcase) { - echo "Now testing function $testcase: remote method to convert U.S. state number into state name"; - $statenum = 25; - $statename = $testcase($statenum, 2); - echo "State number $statenum is " . htmlspecialchars($statename); + if ($testCase) { + echo "Now testing function $testCase: remote method to convert U.S. state number into state name"; + $stateNum = 25; + $stateName = $testCase($stateNum, 2); + echo "State number $stateNum is " . htmlspecialchars($stateName); } } ?> diff --git a/demo/client/zopetest.php b/demo/client/zopetest.php index ea93525..39e705e 100644 --- a/demo/client/zopetest.php +++ b/demo/client/zopetest.php @@ -1,26 +1,28 @@ -xmlrpc +xmlrpc - Zope test demo

Zope test demo

The code demonstrates usage of basic authentication to connect to the server

setCredentials("username", "password"); -$c->setDebug(2); -$r = $c->send($f); -if (!$r->faultCode()) { - $v = $r->value(); - print "I received:" . htmlspecialchars($v->scalarval()) . "
"; +include_once __DIR__ . "/../../src/Autoloader.php"; +PhpXmlRpc\Autoloader::register(); + +$req = new PhpXmlRpc\Request('document_src', array()); +$client = new PhpXmlRpc\Client("pingu.heddley.com:9080/index_html"); +$client->setCredentials("username", "password"); +$client->setDebug(2); +$resp = $client->send($req); +if (!$resp->faultCode()) { + $value = $resp->value(); + print "I received:" . htmlspecialchars($value->scalarval()) . "
"; print "
I got this value back
pre>" . - htmlentities($r->serialize()) . "\n"; + htmlentities($resp->serialize()) . "\n"; } else { print "An error occurred: "; - print "Code: " . htmlspecialchars($r->faultCode()) - . " Reason: '" . ($r->faultString()) . "'
"; + print "Code: " . htmlspecialchars($resp->faultCode()) + . " Reason: '" . ($resp->faultString()) . "'
"; } ?> diff --git a/demo/server/discuss.php b/demo/server/discuss.php index 7e6e4e9..2a137e8 100644 --- a/demo/server/discuss.php +++ b/demo/server/discuss.php @@ -42,11 +42,11 @@ function addcomment($m) } // if we generated an error, create an error return response if ($err) { - return new xmlrpcresp(0, $xmlrpcerruser, $err); + return new PhpXmlRpc\Response(0, $xmlrpcerruser, $err); } else { // otherwise, we create the right response // with the state name - return new xmlrpcresp(new xmlrpcval($count, "int")); + return new PhpXmlRpc\Response(new PhpXmlRpc\Value($count, "int")); } } @@ -80,15 +80,15 @@ function getcomments($m) } // if we generated an error, create an error return response if ($err) { - return new xmlrpcresp(0, $xmlrpcerruser, $err); + return new PhpXmlRpc\Response(0, $xmlrpcerruser, $err); } else { // otherwise, we create the right response // with the state name - return new xmlrpcresp(php_xmlrpc_encode($ra)); + return new PhpXmlRpc\Response(php_xmlrpc_encode($ra)); } } -$s = new xmlrpc_server(array( +$s = new PhpXmlRpc\Server(array( "discuss.addComment" => array( "function" => "addcomment", "signature" => $addcomment_sig, diff --git a/demo/server/proxy.php b/demo/server/proxy.php index c78d890..64ad459 100644 --- a/demo/server/proxy.php +++ b/demo/server/proxy.php @@ -25,7 +25,7 @@ function forward_request($m) // create client $timeout = 0; $url = php_xmlrpc_decode($m->getParam(0)); - $c = new xmlrpc_client($url); + $c = new PhpXmlRpc\Client($url); if ($m->getNumParams() > 3) { // we have to set some options onto the client. // Note that if we do not untaint the received values, warnings might be generated... @@ -53,12 +53,12 @@ function forward_request($m) } // build call for remote server - /// @todo find a weay to forward client info (such as IP) to server, either + /// @todo find a way to forward client info (such as IP) to server, either /// - as xml comments in the payload, or /// - using std http header conventions, such as X-forwarded-for... $method = php_xmlrpc_decode($m->getParam(1)); $pars = $m->getParam(2); - $m = new xmlrpcmsg($method); + $m = new PhpXmlRpc\Request($method); for ($i = 0; $i < $pars->arraySize(); $i++) { $m->addParam($pars->arraymem($i)); } @@ -70,7 +70,7 @@ function forward_request($m) } // run the server -$server = new xmlrpc_server( +$server = new PhpXmlRpc\Server( array( 'xmlrpcproxy.call' => array( 'function' => 'forward_request', diff --git a/demo/server/server.php b/demo/server/server.php index b6fa526..eefaa38 100644 --- a/demo/server/server.php +++ b/demo/server/server.php @@ -43,7 +43,7 @@ class xmlrpc_server_methods_container public function phpwarninggenerator($m) { $a = $b; // this triggers a warning in E_ALL mode, since $b is undefined - return new xmlrpcresp(new xmlrpcval(1, 'boolean')); + return new PhpXmlRpc\Response(new PhpXmlRpc\Value(1, 'boolean')); } /** @@ -108,11 +108,11 @@ function findstate($m) // if we generated an error, create an error return response if ($err) { - return new xmlrpcresp(0, $xmlrpcerruser, $err); + return new PhpXmlRpc\Response(0, $xmlrpcerruser, $err); } else { // otherwise, we create the right response // with the state name - return new xmlrpcresp(new xmlrpcval($sname)); + return new PhpXmlRpc\Response(new PhpXmlRpc\Value($sname)); } } @@ -141,7 +141,7 @@ $findstate3_sig = wrap_php_function(array('xmlrpc_server_methods_container', 'fi $findstate5_sig = wrap_php_function('xmlrpc_server_methods_container::findstate'); -$obj = new xmlrpc_server_methods_container(); +$obj = new PhpXmlRpc\Server_methods_container(); $findstate4_sig = wrap_php_function(array($obj, 'findstate')); $addtwo_sig = array(array($xmlrpcInt, $xmlrpcInt, $xmlrpcInt)); @@ -151,7 +151,7 @@ function addtwo($m) $s = $m->getParam(0); $t = $m->getParam(1); - return new xmlrpcresp(new xmlrpcval($s->scalarval() + $t->scalarval(), "int")); + return new PhpXmlRpc\Response(new PhpXmlRpc\Value($s->scalarval() + $t->scalarval(), "int")); } $addtwodouble_sig = array(array($xmlrpcDouble, $xmlrpcDouble, $xmlrpcDouble)); @@ -161,7 +161,7 @@ function addtwodouble($m) $s = $m->getParam(0); $t = $m->getParam(1); - return new xmlrpcresp(new xmlrpcval($s->scalarval() + $t->scalarval(), "double")); + return new PhpXmlRpc\Response(new PhpXmlRpc\Value($s->scalarval() + $t->scalarval(), "double")); } $stringecho_sig = array(array($xmlrpcString, $xmlrpcString)); @@ -172,7 +172,7 @@ function stringecho($m) $s = $m->getParam(0); $v = $s->scalarval(); - return new xmlrpcresp(new xmlrpcval($s->scalarval())); + return new PhpXmlRpc\Response(new PhpXmlRpc\Value($s->scalarval())); } $echoback_sig = array(array($xmlrpcString, $xmlrpcString)); @@ -185,7 +185,7 @@ function echoback($m) // $m is an incoming message $s = "I got the following message:\n" . $m->serialize(); - return new xmlrpcresp(new xmlrpcval($s)); + return new PhpXmlRpc\Response(new PhpXmlRpc\Value($s)); } $echosixtyfour_sig = array(array($xmlrpcString, $xmlrpcBase64)); @@ -197,7 +197,7 @@ function echosixtyfour($m) // is working as expected $incoming = $m->getParam(0); - return new xmlrpcresp(new xmlrpcval($incoming->scalarval(), "string")); + return new PhpXmlRpc\Response(new PhpXmlRpc\Value($incoming->scalarval(), "string")); } $bitflipper_sig = array(array($xmlrpcArray, $xmlrpcArray)); @@ -208,7 +208,7 @@ function bitflipper($m) $v = $m->getParam(0); $sz = $v->arraysize(); - $rv = new xmlrpcval(array(), $xmlrpcArray); + $rv = new PhpXmlRpc\Value(array(), $xmlrpcArray); for ($j = 0; $j < $sz; $j++) { $b = $v->arraymem($j); @@ -219,7 +219,7 @@ function bitflipper($m) } } - return new xmlrpcresp($rv); + return new PhpXmlRpc\Response($rv); } // Sorting demo @@ -269,7 +269,7 @@ function agesorter($m) // error string for [if|when] things go wrong $err = ""; // create the output value - $v = new xmlrpcval(); + $v = new PhpXmlRpc\Value(); $agar = array(); if (isset($sno) && $sno->kindOf() == "array") { @@ -297,8 +297,8 @@ function agesorter($m) $outAr = array(); while (list($key, $val) = each($agesorter_arr)) { // recreate each struct element - $outAr[] = new xmlrpcval(array("name" => new xmlrpcval($key), - "age" => new xmlrpcval($val, "int"),), "struct"); + $outAr[] = new PhpXmlRpc\Value(array("name" => new PhpXmlRpc\Value($key), + "age" => new PhpXmlRpc\Value($val, "int"),), "struct"); } // add this array to the output value $v->addArray($outAr); @@ -307,9 +307,9 @@ function agesorter($m) } if ($err) { - return new xmlrpcresp(0, $xmlrpcerruser, $err); + return new PhpXmlRpc\Response(0, $xmlrpcerruser, $err); } else { - return new xmlrpcresp($v); + return new PhpXmlRpc\Response($v); } } @@ -378,9 +378,9 @@ function mail_send($m) } if ($err) { - return new xmlrpcresp(0, $xmlrpcerruser, $err); + return new PhpXmlRpc\Response(0, $xmlrpcerruser, $err); } else { - return new xmlrpcresp(new xmlrpcval("true", $xmlrpcBoolean)); + return new PhpXmlRpc\Response(new PhpXmlRpc\Value("true", $xmlrpcBoolean)); } } @@ -390,7 +390,7 @@ function getallheaders_xmlrpc($m) { global $xmlrpcerruser; if (function_exists('getallheaders')) { - return new xmlrpcresp(php_xmlrpc_encode(getallheaders())); + return new PhpXmlRpc\Response(php_xmlrpc_encode(getallheaders())); } else { $headers = array(); // IIS: poor man's version of getallheaders @@ -401,7 +401,7 @@ function getallheaders_xmlrpc($m) } } - return new xmlrpcresp(php_xmlrpc_encode($headers)); + return new PhpXmlRpc\Response(php_xmlrpc_encode($headers)); } } @@ -415,14 +415,14 @@ function setcookies($m) setcookie($name, @$cookiedesc['value'], @$cookiedesc['expires'], @$cookiedesc['path'], @$cookiedesc['domain'], @$cookiedesc['secure']); } - return new xmlrpcresp(new xmlrpcval(1, 'int')); + return new PhpXmlRpc\Response(new PhpXmlRpc\Value(1, 'int')); } $getcookies_sig = array(array($xmlrpcStruct)); $getcookies_doc = 'Sends to client a response containing all http cookies as received in the request (as struct)'; function getcookies($m) { - return new xmlrpcresp(php_xmlrpc_encode($_COOKIE)); + return new PhpXmlRpc\Response(php_xmlrpc_encode($_COOKIE)); } $v1_arrayOfStructs_sig = array(array($xmlrpcInt, $xmlrpcArray)); @@ -441,7 +441,7 @@ function v1_arrayOfStructs($m) } } - return new xmlrpcresp(new xmlrpcval($numcurly, "int")); + return new PhpXmlRpc\Response(new PhpXmlRpc\Value($numcurly, "int")); } $v1_easyStruct_sig = array(array($xmlrpcInt, $xmlrpcStruct)); @@ -454,7 +454,7 @@ function v1_easyStruct($m) $curly = $sno->structmem("curly"); $num = $moe->scalarval() + $larry->scalarval() + $curly->scalarval(); - return new xmlrpcresp(new xmlrpcval($num, "int")); + return new PhpXmlRpc\Response(new PhpXmlRpc\Value($num, "int")); } $v1_echoStruct_sig = array(array($xmlrpcStruct, $xmlrpcStruct)); @@ -463,7 +463,7 @@ function v1_echoStruct($m) { $sno = $m->getParam(0); - return new xmlrpcresp($sno); + return new PhpXmlRpc\Response($sno); } $v1_manyTypes_sig = array(array( @@ -474,7 +474,7 @@ $v1_manyTypes_sig = array(array( $v1_manyTypes_doc = 'This handler takes six parameters, and returns an array containing all the parameters.'; function v1_manyTypes($m) { - return new xmlrpcresp(new xmlrpcval(array( + return new PhpXmlRpc\Response(new PhpXmlRpc\Value(array( $m->getParam(0), $m->getParam(1), $m->getParam(2), @@ -494,7 +494,7 @@ function v1_moderateSizeArrayCheck($m) $first = $ar->arraymem(0); $last = $ar->arraymem($sz - 1); - return new xmlrpcresp(new xmlrpcval($first->scalarval() . + return new PhpXmlRpc\Response(new PhpXmlRpc\Value($first->scalarval() . $last->scalarval(), "string")); } @@ -505,10 +505,10 @@ function v1_simpleStructReturn($m) $sno = $m->getParam(0); $v = $sno->scalarval(); - return new xmlrpcresp(new xmlrpcval(array( - "times10" => new xmlrpcval($v * 10, "int"), - "times100" => new xmlrpcval($v * 100, "int"), - "times1000" => new xmlrpcval($v * 1000, "int"),), + return new PhpXmlRpc\Response(new PhpXmlRpc\Value(array( + "times10" => new PhpXmlRpc\Value($v * 10, "int"), + "times100" => new PhpXmlRpc\Value($v * 100, "int"), + "times1000" => new PhpXmlRpc\Value($v * 1000, "int"),), "struct" )); } @@ -526,7 +526,7 @@ function v1_nestedStruct($m) $larry = $fools->structmem("larry"); $moe = $fools->structmem("moe"); - return new xmlrpcresp(new xmlrpcval($curly->scalarval() + $larry->scalarval() + $moe->scalarval(), "int")); + return new PhpXmlRpc\Response(new PhpXmlRpc\Value($curly->scalarval() + $larry->scalarval() + $moe->scalarval(), "int")); } $v1_countTheEntities_sig = array(array($xmlrpcStruct, $xmlrpcString)); @@ -563,12 +563,12 @@ function v1_countTheEntities($m) } } - return new xmlrpcresp(new xmlrpcval(array( - "ctLeftAngleBrackets" => new xmlrpcval($lt, "int"), - "ctRightAngleBrackets" => new xmlrpcval($gt, "int"), - "ctAmpersands" => new xmlrpcval($amp, "int"), - "ctApostrophes" => new xmlrpcval($ap, "int"), - "ctQuotes" => new xmlrpcval($qu, "int"),), + return new PhpXmlRpc\Response(new PhpXmlRpc\Value(array( + "ctLeftAngleBrackets" => new PhpXmlRpc\Value($lt, "int"), + "ctRightAngleBrackets" => new PhpXmlRpc\Value($gt, "int"), + "ctAmpersands" => new PhpXmlRpc\Value($amp, "int"), + "ctApostrophes" => new PhpXmlRpc\Value($ap, "int"), + "ctQuotes" => new PhpXmlRpc\Value($qu, "int"),), "struct" )); } @@ -613,7 +613,7 @@ function i_echoParam($m) { $s = $m->getParam(0); - return new xmlrpcresp($s); + return new PhpXmlRpc\Response($s); } function i_echoString($m) @@ -684,7 +684,7 @@ function i_whichToolkit($m) "toolkitOperatingSystem" => isset($SERVER_SOFTWARE) ? $SERVER_SOFTWARE : $_SERVER['SERVER_SOFTWARE'], ); - return new xmlrpcresp(php_xmlrpc_encode($ret)); + return new PhpXmlRpc\Response(php_xmlrpc_encode($ret)); } $o = new xmlrpc_server_methods_container(); @@ -874,7 +874,7 @@ if ($findstate5_sig) { $a['examples.php4.getStateName'] = $findstate5_sig; } -$s = new xmlrpc_server($a, false); +$s = new PhpXmlRpc\Server($a, false); $s->setdebug(3); $s->compress_response = true; diff --git a/demo/vardemo.php b/demo/vardemo.php index 0b542e7..4f91deb 100644 --- a/demo/vardemo.php +++ b/demo/vardemo.php @@ -6,43 +6,43 @@ include_once __DIR__ . "/../vendor/autoload.php"; include_once __DIR__ . "/../lib/xmlrpc.inc"; -$f = new xmlrpcmsg('examples.getStateName'); +$f = new PhpXmlRpc\Request('examples.getStateName'); print "

Testing value serialization

\n"; -$v = new xmlrpcval(23, "int"); +$v = new PhpXmlRpc\Value(23, "int"); print "
" . htmlentities($v->serialize()) . "
"; -$v = new xmlrpcval("What are you saying? >> << &&"); +$v = new PhpXmlRpc\Value("What are you saying? >> << &&"); print "
" . htmlentities($v->serialize()) . "
"; -$v = new xmlrpcval(array( - new xmlrpcval("ABCDEFHIJ"), - new xmlrpcval(1234, 'int'), - new xmlrpcval(1, 'boolean'),), +$v = new PhpXmlRpc\Value(array( + new PhpXmlRpc\Value("ABCDEFHIJ"), + new PhpXmlRpc\Value(1234, 'int'), + new PhpXmlRpc\Value(1, 'boolean'),), "array" ); print "
" . htmlentities($v->serialize()) . "
"; -$v = new xmlrpcval( +$v = new PhpXmlRpc\Value( array( - "thearray" => new xmlrpcval( + "thearray" => new PhpXmlRpc\Value( array( - new xmlrpcval("ABCDEFHIJ"), - new xmlrpcval(1234, 'int'), - new xmlrpcval(1, 'boolean'), - new xmlrpcval(0, 'boolean'), - new xmlrpcval(true, 'boolean'), - new xmlrpcval(false, 'boolean'), + new PhpXmlRpc\Value("ABCDEFHIJ"), + new PhpXmlRpc\Value(1234, 'int'), + new PhpXmlRpc\Value(1, 'boolean'), + new PhpXmlRpc\Value(0, 'boolean'), + new PhpXmlRpc\Value(true, 'boolean'), + new PhpXmlRpc\Value(false, 'boolean'), ), "array" ), - "theint" => new xmlrpcval(23, 'int'), - "thestring" => new xmlrpcval("foobarwhizz"), - "thestruct" => new xmlrpcval( + "theint" => new PhpXmlRpc\Value(23, 'int'), + "thestring" => new PhpXmlRpc\Value("foobarwhizz"), + "thestruct" => new PhpXmlRpc\Value( array( - "one" => new xmlrpcval(1, 'int'), - "two" => new xmlrpcval(2, 'int'), + "one" => new PhpXmlRpc\Value(1, 'int'), + "two" => new PhpXmlRpc\Value(2, 'int'), ), "struct" ), @@ -52,11 +52,11 @@ $v = new xmlrpcval( print "
" . htmlentities($v->serialize()) . "
"; -$w = new xmlrpcval(array($v, new xmlrpcval("That was the struct!")), "array"); +$w = new PhpXmlRpc\Value(array($v, new PhpXmlRpc\Value("That was the struct!")), "array"); print "
" . htmlentities($w->serialize()) . "
"; -$w = new xmlrpcval("Mary had a little lamb, +$w = new PhpXmlRpc\Value("Mary had a little lamb, Whose fleece was white as snow, And everywhere that Mary went the lamb was sure to go. @@ -70,7 +70,7 @@ print "
" . htmlentities($w->serialize()) . "
"; print "
Value of base64 string is: '" . $w->scalarval() . "'
"; $f->method(''); -$f->addParam(new xmlrpcval("41", "int")); +$f->addParam(new PhpXmlRpc\Value("41", "int")); print "

Testing request serialization

\n"; $op = $f->serialize(); -- 2.43.0