X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=demo%2Fclient%2Fagesort.php;h=90622d21a3c603c15b3b77a7ba85fd92f076f1be;hb=a48c09b3cc49bc7f603cd5b06de74ee2d2878ca4;hp=8ae87ff765bc3c5bea6473f86d867fe84a75e2d6;hpb=5b0b061574fa8458d5a92c24c20d077ad832cf63;p=plcapi.git diff --git a/demo/client/agesort.php b/demo/client/agesort.php index 8ae87ff..90622d2 100644 --- a/demo/client/agesort.php +++ b/demo/client/agesort.php @@ -1 +1,68 @@ - xmlrpc

Agesort demo

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

24, "Edd" => 45, "Joe" => 37, "Fred" => 27); reset($inAr); print "This is the input data:
";
while (list($key, $val) = each($inAr)) {
    print $key . ", " . $val . "\n";
}
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"); } $v = new xmlrpcval($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); // set maximum debug level, to have the complete communication printed to screen $c->setDebug(2); // send request print "Now sending request (detailed debug info follows)"; $r = &$c->send($f); // check response for errors, and take appropriate action if (!$r->faultCode()) { print "The server gave me these results:
";
    $v = $r->value();
    $max = $v->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";
    }

    print "
For nerds: I got this value back
" .
        htmlentities($r->serialize()) . "

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

'; } ?> \ No newline at end of file + +xmlrpc - Agesort demo + +

Agesort demo

+ +

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

+ +

+ 24, "Edd" => 45, "Joe" => 37, "Fred" => 27); +print "This is the input data:
";
+foreach($inAr as $key => $val) {
+    print $key . ", " . $val . "\n";
+}
+print "
"; + +// create parameters from the input array: an xmlrpc array of xmlrpc structs +$p = array(); +foreach ($inAr as $key => $val) { + $p[] = new PhpXmlRpc\Value( + array( + "name" => new PhpXmlRpc\Value($key), + "age" => new PhpXmlRpc\Value($val, "int") + ), + "struct" + ); +} +$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 +$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 +$client->setDebug(2); + +// send request +print "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:
";
+    $value = $resp->value();
+    foreach ($value as $struct) {
+        $name = $struct["name"];
+        $age = $struct["age"];
+        print htmlspecialchars($name->scalarval()) . ", " . htmlspecialchars($age->scalarval()) . "\n";
+    }
+
+    print "
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()) . '\'

'; +} + +?> + +