X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=demo%2Fclient%2Fintrospect.php;h=e11ac0e5e4f2ad26fb07a7ced9974d9aa6acd30f;hb=92e61c97411b8652b235e9c05d64934d83c53671;hp=7200604814b05acf01f604a5aad18d9e436e23f6;hpb=a518f173b88b757ad83e694d088331fe5496d977;p=plcapi.git diff --git a/demo/client/introspect.php b/demo/client/introspect.php index 7200604..e11ac0e 100644 --- a/demo/client/introspect.php +++ b/demo/client/introspect.php @@ -15,26 +15,31 @@ function display_error($r) print "Code: " . $r->faultCode() . " Reason: '" . $r->faultString() . "'
"; } -// 'new style' client constructor + $client = new PhpXmlRpc\Client("http://phpxmlrpc.sourceforge.net/server.php"); + +// First off, let's retrieve the list of methods available on the remote server print "

methods available at http://" . $client->server . $client->path . "

\n"; $req = new PhpXmlRpc\Request('system.listMethods'); $resp = $client->send($req); + if ($resp->faultCode()) { display_error($resp); } else { $v = $resp->value(); + + // Then, retrieve the signature and help text of each available method for ($i = 0; $i < $v->arraysize(); $i++) { - $mname = $v->arraymem($i); - print "

" . $mname->scalarval() . "

\n"; + $methodName = $v->arraymem($i); + print "

" . $methodName->scalarval() . "

\n"; // build messages first, add params later $m1 = new PhpXmlRpc\Request('system.methodHelp'); $m2 = new PhpXmlRpc\Request('system.methodSignature'); - $val = new PhpXmlRpc\Value($mname->scalarval(), "string"); + $val = new PhpXmlRpc\Value($methodName->scalarval(), "string"); $m1->addParam($val); $m2->addParam($val); - // send multiple messages in one pass. - // If server does not support multicall, client will fall back to 2 separate calls + // Send multiple requests in one http call. + // If server does not support multicall, client will automatically fall back to 2 separate calls $ms = array($m1, $m2); $rs = $client->send($ms); if ($rs[0]->faultCode()) { @@ -52,13 +57,14 @@ if ($resp->faultCode()) { display_error($rs[1]); } else { print "

Signature

\n"; + // note: using PhpXmlRpc\Encoder::decode() here would lead to cleaner code $val = $rs[1]->value(); if ($val->kindOf() == "array") { for ($j = 0; $j < $val->arraysize(); $j++) { $x = $val->arraymem($j); $ret = $x->arraymem(0); print "" . $ret->scalarval() . " " - . $mname->scalarval() . "("; + . $methodName->scalarval() . "("; if ($x->arraysize() > 1) { for ($k = 1; $k < $x->arraysize(); $k++) { $y = $x->arraymem($k);