X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=demo%2Fclient%2Fwrap.php;h=4dde5ba023fb189dff541327e8d6a12427aa1bc6;hb=92e61c97411b8652b235e9c05d64934d83c53671;hp=8ec452cd013fad5e339465d203436fe924c5f9a8;hpb=e2ef0823a57f66ef5260006a2d08528428457c84;p=plcapi.git
diff --git a/demo/client/wrap.php b/demo/client/wrap.php
index 8ec452c..4dde5ba 100644
--- a/demo/client/wrap.php
+++ b/demo/client/wrap.php
@@ -1,56 +1,53 @@
-
xmlrpc
+xmlrpc - Webservice wrappper demo
Webservice wrappper demo
+
Wrap methods exposed by server into php functions
-The code demonstrates usage of the most automagic client usage possible:
-1) client that returns php values instead of xmlrpcval objects
-2) wrapping of remote methods into php functions
+
+The code demonstrates usage of some the most automagic client usage possible:
+ 1) client that returns php values instead of xmlrpc value objects
+ 2) wrapping of remote methods into php functions
+ See also proxy.php for an alternative take
return_type = 'phpvals'; // let client give us back php values instead of xmlrpcvals
- $r =& $c->send(new xmlrpcmsg('system.listMethods'));
- if($r->faultCode())
- {
- echo "
Server methods list could not be retrieved: error '".htmlspecialchars($r->faultString())."'
\n";
- }
- else
- {
- $testcase = '';
- echo "Server methods list retrieved, now wrapping it up...
\n\n";
- foreach($r->value() as $methodname) // $r->value is an array of strings
- {
- // do not wrap remote server system methods
- if (strpos($methodname, 'system.') !== 0)
- {
- $funcname = wrap_xmlrpc_method($c, $methodname);
- if($funcname)
- {
- echo "- Remote server method ".htmlspecialchars($methodname)." wrapped into php function ".$funcname."
\n";
- }
- else
- {
- echo "- Remote server method ".htmlspecialchars($methodname)." could not be wrapped!
\n";
- }
- if($methodname == 'examples.getStateName')
- {
- $testcase = $funcname;
- }
+include_once __DIR__ . "/../../src/Autoloader.php";
+PhpXmlRpc\Autoloader::register();
+
+$client = new PhpXmlRpc\Client("http://phpxmlrpc.sourceforge.net/server.php");
+$client->return_type = 'phpvals'; // let client give us back php values instead of xmlrpcvals
+$resp = $client->send(new PhpXmlRpc\Request('system.listMethods'));
+if ($resp->faultCode()) {
+ echo "Server methods list could not be retrieved: error {$resp->faultCode()} '" . htmlspecialchars($resp->faultString()) . "'
\n";
+} else {
+ $testCase = '';
+ $wrapper = new PhpXmlRpc\Wrapper();
+ echo "Server methods list retrieved, now wrapping it up...
\n\n";
+ foreach ($resp->value() as $methodName) {
+ // $resp->value is an array of strings
+
+ // do not wrap remote server system methods
+ if (strpos($methodName, 'system.') !== 0) {
+ $funcName = $wrapper->wrap_xmlrpc_method($client, $methodName);
+ if ($funcName) {
+ echo "- Remote server method " . htmlspecialchars($methodName) . " wrapped into php function " . $funcName . "
\n";
+ } else {
+ echo "- Remote server method " . htmlspecialchars($methodName) . " could not be wrapped!
\n";
+ }
+ if ($methodName == 'examples.getStateName') {
+ $testCase = $funcName;
}
}
- echo "
\n";
- if($testcase)
- {
- echo "Now testing function $testcase: remote method to convert U.S. state number into state name";
- $statenum = 25;
- $statename = $testcase($statenum, 2);
- echo "State number $statenum is ".htmlspecialchars($statename);
- }
}
+ echo "
\n";
+ if ($testCase) {
+ echo "Now testing function $testCase: remote method to convert U.S. state number into state name";
+ $stateNum = rand(1, 51);
+ $stateName = $testCase($stateNum, 2);
+ echo "State number $stateNum is " . htmlspecialchars($stateName);
+ }
+}
?>