2 <head><title>xmlrpc - Introspect demo</title></head>
4 <h1>Introspect demo</h1>
5 <h2>Query server for available methods and their description</h2>
6 <h3>The code demonstrates usage of multicall and introspection methods</h3>
9 include_once __DIR__ . "/../../src/Autoloader.php";
10 PhpXmlRpc\Autoloader::register();
12 function display_error($r)
14 print "An error occurred: ";
15 print "Code: " . $r->faultCode()
16 . " Reason: '" . $r->faultString() . "'<br/>";
19 $client = new PhpXmlRpc\Client("http://phpxmlrpc.sourceforge.net/server.php");
21 // First off, let's retrieve the list of methods available on the remote server
22 print "<h3>methods available at http://" . $client->server . $client->path . "</h3>\n";
23 $req = new PhpXmlRpc\Request('system.listMethods');
24 $resp = $client->send($req);
26 if ($resp->faultCode()) {
31 // Then, retrieve the signature and help text of each available method
32 foreach ($v as $methodName) {
33 print "<h4>" . $methodName->scalarval() . "</h4>\n";
34 // build messages first, add params later
35 $m1 = new PhpXmlRpc\Request('system.methodHelp');
36 $m2 = new PhpXmlRpc\Request('system.methodSignature');
37 $val = new PhpXmlRpc\Value($methodName->scalarval(), "string");
40 // Send multiple requests in one http call.
41 // If server does not support multicall, client will automatically fall back to 2 separate calls
42 $ms = array($m1, $m2);
43 $rs = $client->send($ms);
44 if ($rs[0]->faultCode()) {
45 display_error($rs[0]);
47 $val = $rs[0]->value();
48 $txt = $val->scalarval();
50 print "<h4>Documentation</h4><p>${txt}</p>\n";
52 print "<p>No documentation available.</p>\n";
55 if ($rs[1]->faultCode()) {
56 display_error($rs[1]);
58 print "<h4>Signature</h4><p>\n";
59 // note: using PhpXmlRpc\Encoder::decode() here would lead to cleaner code
60 $val = $rs[1]->value();
61 if ($val->kindOf() == "array") {
62 foreach ($val as $x) {
64 print "<code>" . $ret->scalarval() . " "
65 . $methodName->scalarval() . "(";
66 if ($x->count() > 1) {
67 for ($k = 1; $k < $x->count(); $k++) {
69 print $y->scalarval();
70 if ($k < $x->count() - 1) {
75 print ")</code><br/>\n";
78 print "Signature unknown\n";