X-Git-Url: http://git.onelab.eu/?p=plcapi.git;a=blobdiff_plain;f=php%2Fphpxmlrpc%2Fdemo%2Fclient%2Fintrospect.php;fp=php%2Fphpxmlrpc%2Fdemo%2Fclient%2Fintrospect.php;h=7870a94cc2d47fd080ec696ebde387f08504c1bd;hp=0000000000000000000000000000000000000000;hb=21d187714285d9818fd94509b015ba069facb7ef;hpb=9bd41316bc9541bbedfe45377089d4e4927129b1 diff --git a/php/phpxmlrpc/demo/client/introspect.php b/php/phpxmlrpc/demo/client/introspect.php new file mode 100644 index 0000000..7870a94 --- /dev/null +++ b/php/phpxmlrpc/demo/client/introspect.php @@ -0,0 +1,86 @@ + +xmlrpc - Introspect demo + +

Introspect demo

+

Query server for available methods and their description

+

The code demonstrates usage of multicall and introspection methods

+faultCode() + . " Reason: '" . $r->faultString() . "'
"; +} + +$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 + foreach ($v as $methodName) { + 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($methodName->scalarval(), "string"); + $m1->addParam($val); + $m2->addParam($val); + // 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()) { + display_error($rs[0]); + } else { + $val = $rs[0]->value(); + $txt = $val->scalarval(); + if ($txt != "") { + print "

Documentation

${txt}

\n"; + } else { + print "

No documentation available.

\n"; + } + } + if ($rs[1]->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") { + foreach ($val as $x) { + $ret = $x[0]; + print "" . $ret->scalarval() . " " + . $methodName->scalarval() . "("; + if ($x->count() > 1) { + for ($k = 1; $k < $x->count(); $k++) { + $y = $x[$k]; + print $y->scalarval(); + if ($k < $x->count() - 1) { + print ", "; + } + } + } + print ")
\n"; + } + } else { + print "Signature unknown\n"; + } + print "

\n"; + } + } +} +?> + +