Fix newlines (to satisfy automated code quality scanners)
[plcapi.git] / demo / client / introspect.php
1 <html>
2 <head><title>xmlrpc</title></head>
3 <body>
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>
7 <?php
8 include "xmlrpc.inc";
9 function display_error($r)
10 {
11     print "An error occurred: ";
12     print "Code: " . $r->faultCode()
13         . " Reason: '" . $r->faultString() . "'<br/>";
14 }
15 // 'new style' client constructor
16 $c = new xmlrpc_client("http://phpxmlrpc.sourceforge.net/server.php");
17 print "<h3>methods available at http://" . $c->server . $c->path . "</h3>\n";
18 $m = new xmlrpcmsg('system.listMethods');
19 $r = &$c->send($m);
20 if ($r->faultCode()) {
21     display_error($r);
22 } else {
23     $v = $r->value();
24     for ($i = 0; $i < $v->arraysize(); $i++) {
25         $mname = $v->arraymem($i);
26         print "<h4>" . $mname->scalarval() . "</h4>\n";
27         // build messages first, add params later
28         $m1 = new xmlrpcmsg('system.methodHelp');
29         $m2 = new xmlrpcmsg('system.methodSignature');
30         $val = new xmlrpcval($mname->scalarval(), "string");
31         $m1->addParam($val);
32         $m2->addParam($val);
33         // send multiple messages in one pass.
34         // If server does not support multicall, client will fall back to 2 separate calls
35         $ms = array($m1, $m2);
36         $rs = &$c->send($ms);
37         if ($rs[0]->faultCode()) {
38             display_error($rs[0]);
39         } else {
40             $val = $rs[0]->value();
41             $txt = $val->scalarval();
42             if ($txt != "") {
43                 print "<h4>Documentation</h4><p>${txt}</p>\n";
44             } else {
45                 print "<p>No documentation available.</p>\n";
46             }
47         }
48         if ($rs[1]->faultCode()) {
49             display_error($rs[1]);
50         } else {
51             print "<h4>Signature</h4><p>\n";
52             $val = $rs[1]->value();
53             if ($val->kindOf() == "array") {
54                 for ($j = 0; $j < $val->arraysize(); $j++) {
55                     $x = $val->arraymem($j);
56                     $ret = $x->arraymem(0);
57                     print "<code>" . $ret->scalarval() . " "
58                         . $mname->scalarval() . "(";
59                     if ($x->arraysize() > 1) {
60                         for ($k = 1; $k < $x->arraysize(); $k++) {
61                             $y = $x->arraymem($k);
62                             print $y->scalarval();
63                             if ($k < $x->arraysize() - 1) {
64                                 print ", ";
65                             }
66                         }
67                     }
68                     print ")</code><br/>\n";
69                 }
70             } else {
71                 print "Signature unknown\n";
72             }
73             print "</p>\n";
74         }
75     }
76 }
77 ?>
78 </body>
79 </html>