1 <?php require_once __DIR__ . "/_prepend.php"; ?><html lang="en">
2 <head><title>xmlrpc - Webservice wrappper demo</title></head>
4 <h1>Webservice wrappper demo</h1>
6 <h2>Wrap methods exposed by server into php functions</h2>
8 <h3>The code demonstrates usage of some the most automagic client usage possible:<br/>
9 1) client that returns php values instead of xmlrpc value objects<br/>
10 2) wrapping of remote methods into php functions<br/>
11 See also proxy.php for an alternative take
13 <p>You can see the source to this page here: <a href="wrap.php?showSource=1">wrap.php</a></p>
16 $client = new PhpXmlRpc\Client(XMLRPCSERVER);
17 $client->return_type = 'phpvals'; // let client give us back php values instead of xmlrpcvals
18 $resp = $client->send(new PhpXmlRpc\Request('system.listMethods'));
19 if ($resp->faultCode()) {
20 echo "<p>Server methods list could not be retrieved: error {$resp->faultCode()} '" . htmlspecialchars($resp->faultString()) . "'</p>\n";
22 echo "<p>Server methods list retrieved, now wrapping it up...</p>\n<ul>\n";
26 $wrapper = new PhpXmlRpc\Wrapper();
27 foreach ($resp->value() as $methodName) {
28 // $resp->value is an array of strings
29 if ($methodName == 'examples.getStateName') {
30 $callable = $wrapper->wrapXmlrpcMethod($client, $methodName);
32 echo "<li>Remote server method " . htmlspecialchars($methodName) . " wrapped into php function</li>\n";
34 echo "<li>Remote server method " . htmlspecialchars($methodName) . " could not be wrapped!</li>\n";
43 echo "Now testing function for remote method to convert U.S. state number into state name";
44 $stateNum = rand(1, 51);
45 // the 2nd parameter gets added to the closure - it is the debug level to be used for the client
46 $stateName = $callable($stateNum, 2);
47 echo "State $stateNum is ".htmlspecialchars($stateName);
52 </html><?php require_once __DIR__ . "/_append.php"; ?>