6b4e005d02a0acd84f0cc5d3b14a715d8e8be9c9
[plcapi.git] / demo / client / wrap.php
1 <html>
2 <head><title>xmlrpc</title></head>
3 <body>
4 <h1>Webservice wrappper demo</h1>
5 <h2>Wrap methods exposed by server into php functions</h2>
6 <h3>The code demonstrates usage of the most automagic client usage possible:<br/>
7 1) client that returns php values instead of xmlrpcval objects<br/>
8 2) wrapping of remote methods into php functions
9 </h3>
10 <?php
11         include("xmlrpc.inc");
12         include("xmlrpc_wrappers.inc");
13
14         $c = new xmlrpc_client("/server.php", "phpxmlrpc.sourceforge.net", 80);
15         $c->return_type = 'phpvals'; // let client give us back php values instead of xmlrpcvals
16         $r =& $c->send(new xmlrpcmsg('system.listMethods'));
17         if($r->faultCode())
18         {
19                 echo "<p>Server methods list could not be retrieved: error '".htmlspecialchars($r->faultString())."'</p>\n";
20         }
21         else
22         {
23                 $testcase = '';
24                 echo "<p>Server methods list retrieved, now wrapping it up...</p>\n<ul>\n";
25                 foreach($r->value() as $methodname) // $r->value is an array of strings
26                 {
27                         // do not wrap remote server system methods
28                         if (strpos($methodname, 'system.') !== 0)
29                         {
30                                 $funcname = wrap_xmlrpc_method($c, $methodname);
31                                 if($funcname)
32                                 {
33                                         echo "<li>Remote server method ".htmlspecialchars($methodname)." wrapped into php function ".$funcname."</li>\n";
34                                 }
35                                 else
36                                 {
37                                         echo "<li>Remote server method ".htmlspecialchars($methodname)." could not be wrapped!</li>\n";
38                                 }
39                                 if($methodname == 'examples.getStateName')
40                                 {
41                                         $testcase = $funcname;
42                                 }
43                         }
44                 }
45                 echo "</ul>\n";
46                 if($testcase)
47                 {
48                         echo "Now testing function $testcase: remote method to convert U.S. state number into state name";
49                         $statenum = 25;
50                         $statename = $testcase($statenum, 2);
51                         echo "State number $statenum is ".htmlspecialchars($statename);
52                 }
53         }
54 ?>
55 <hr/>
56 <em>$Id$</em>
57 </body>
58 </html>