<html>
-<head><title>xmlrpc</title></head>
+<head><title>xmlrpc - Agesort demo</title></head>
<body>
<h1>Agesort demo</h1>
<p></p>
<?php
-include "xmlrpc.inc";
+
+include_once __DIR__ . "/../../src/Autoloader.php";
+PhpXmlRpc\Autoloader::register();
$inAr = array("Dave" => 24, "Edd" => 45, "Joe" => 37, "Fred" => 27);
-reset($inAr);
print "This is the input data:<br/><pre>";
-while (list($key, $val) = each($inAr)) {
+foreach($inAr as $key => $val) {
print $key . ", " . $val . "\n";
}
print "</pre>";
// 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: <pre>\n" . htmlentities($v->serialize()) . "</pre>\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:<pre>";
- $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";
+ $value = $resp->value();
+ foreach ($value as $struct) {
+ $name = $struct->structmem("name");
+ $age = $struct->structmem("age");
+ print htmlspecialchars($name->scalarval()) . ", " . htmlspecialchars($age->scalarval()) . "\n";
}
print "<hr/>For nerds: I got this value back<br/><pre>" .
- htmlentities($r->serialize()) . "</pre><hr/>\n";
+ htmlentities($resp->serialize()) . "</pre><hr/>\n";
} else {
print "An error occurred:<pre>";
- print "Code: " . htmlspecialchars($r->faultCode()) .
- "\nReason: '" . htmlspecialchars($r->faultString()) . '\'</pre><hr/>';
+ print "Code: " . htmlspecialchars($resp->faultCode()) .
+ "\nReason: '" . htmlspecialchars($resp->faultString()) . '\'</pre><hr/>';
}
?>