first commit
This commit is contained in:
68
lib/phpxmlrpc/demo/client/agesort.php
Normal file
68
lib/phpxmlrpc/demo/client/agesort.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<html>
|
||||
<head><title>xmlrpc - Agesort demo</title></head>
|
||||
<body>
|
||||
<h1>Agesort demo</h1>
|
||||
|
||||
<h2>Send an array of 'name' => 'age' pairs to the server that will send it back sorted.</h2>
|
||||
|
||||
<h3>The source code demonstrates basic lib usage, including handling of xmlrpc arrays and structs</h3>
|
||||
|
||||
<p></p>
|
||||
<?php
|
||||
|
||||
include_once __DIR__ . "/../../src/Autoloader.php";
|
||||
PhpXmlRpc\Autoloader::register();
|
||||
|
||||
$inAr = array("Dave" => 24, "Edd" => 45, "Joe" => 37, "Fred" => 27);
|
||||
print "This is the input data:<br/><pre>";
|
||||
foreach($inAr as $key => $val) {
|
||||
print $key . ", " . $val . "\n";
|
||||
}
|
||||
print "</pre>";
|
||||
|
||||
// create parameters from the input array: an xmlrpc array of xmlrpc structs
|
||||
$p = array();
|
||||
foreach ($inAr as $key => $val) {
|
||||
$p[] = new PhpXmlRpc\Value(
|
||||
array(
|
||||
"name" => new PhpXmlRpc\Value($key),
|
||||
"age" => new PhpXmlRpc\Value($val, "int")
|
||||
),
|
||||
"struct"
|
||||
);
|
||||
}
|
||||
$v = new PhpXmlRpc\Value($p, "array");
|
||||
print "Encoded into xmlrpc format it looks like this: <pre>\n" . htmlentities($v->serialize()) . "</pre>\n";
|
||||
|
||||
// create client and message objects
|
||||
$req = new PhpXmlRpc\Request('examples.sortByAge', array($v));
|
||||
$client = new PhpXmlRpc\Client("http://phpxmlrpc.sourceforge.net/server.php");
|
||||
|
||||
// set maximum debug level, to have the complete communication printed to screen
|
||||
$client->setDebug(2);
|
||||
|
||||
// send request
|
||||
print "Now sending request (detailed debug info follows)";
|
||||
$resp = $client->send($req);
|
||||
|
||||
// check response for errors, and take appropriate action
|
||||
if (!$resp->faultCode()) {
|
||||
print "The server gave me these results:<pre>";
|
||||
$value = $resp->value();
|
||||
foreach ($value as $struct) {
|
||||
$name = $struct["name"];
|
||||
$age = $struct["age"];
|
||||
print htmlspecialchars($name->scalarval()) . ", " . htmlspecialchars($age->scalarval()) . "\n";
|
||||
}
|
||||
|
||||
print "<hr/>For nerds: I got this value back<br/><pre>" .
|
||||
htmlentities($resp->serialize()) . "</pre><hr/>\n";
|
||||
} else {
|
||||
print "An error occurred:<pre>";
|
||||
print "Code: " . htmlspecialchars($resp->faultCode()) .
|
||||
"\nReason: '" . htmlspecialchars($resp->faultString()) . '\'</pre><hr/>';
|
||||
}
|
||||
|
||||
?>
|
||||
</body>
|
||||
</html>
|
||||
43
lib/phpxmlrpc/demo/client/getstatename.php
Normal file
43
lib/phpxmlrpc/demo/client/getstatename.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<html>
|
||||
<head><title>xmlrpc - Getstatename demo</title></head>
|
||||
<body>
|
||||
<h1>Getstatename demo</h1>
|
||||
|
||||
<h2>Send a U.S. state number to the server and get back the state name</h2>
|
||||
|
||||
<h3>The code demonstrates usage of automatic encoding/decoding of php variables into xmlrpc values</h3>
|
||||
<?php
|
||||
|
||||
include_once __DIR__ . "/../../src/Autoloader.php";
|
||||
PhpXmlRpc\Autoloader::register();
|
||||
|
||||
if (isset($_POST["stateno"]) && $_POST["stateno"] != "") {
|
||||
$stateNo = (integer)$_POST["stateno"];
|
||||
$encoder = new PhpXmlRpc\Encoder();
|
||||
$req = new PhpXmlRpc\Request('examples.getStateName',
|
||||
array($encoder->encode($stateNo))
|
||||
);
|
||||
print "Sending the following request:<pre>\n\n" . htmlentities($req->serialize()) . "\n\n</pre>Debug info of server data follows...\n\n";
|
||||
$client = new PhpXmlRpc\Client("http://phpxmlrpc.sourceforge.net/server.php");
|
||||
$client->setDebug(1);
|
||||
$r = $client->send($req);
|
||||
if (!$r->faultCode()) {
|
||||
$v = $r->value();
|
||||
print "<br/>State number <b>" . $stateNo . "</b> is <b>"
|
||||
. htmlspecialchars($encoder->decode($v)) . "</b><br/>";
|
||||
} else {
|
||||
print "An error occurred: ";
|
||||
print "Code: " . htmlspecialchars($r->faultCode())
|
||||
. " Reason: '" . htmlspecialchars($r->faultString()) . "'</pre><br/>";
|
||||
}
|
||||
} else {
|
||||
$stateNo = "";
|
||||
}
|
||||
|
||||
print "<form action=\"getstatename.php\" method=\"POST\">
|
||||
<input name=\"stateno\" value=\"" . $stateNo . "\"><input type=\"submit\" value=\"go\" name=\"submit\"></form>
|
||||
<p>Enter a state number to query its name</p>";
|
||||
|
||||
?>
|
||||
</body>
|
||||
</html>
|
||||
86
lib/phpxmlrpc/demo/client/introspect.php
Normal file
86
lib/phpxmlrpc/demo/client/introspect.php
Normal file
@@ -0,0 +1,86 @@
|
||||
<html>
|
||||
<head><title>xmlrpc - Introspect demo</title></head>
|
||||
<body>
|
||||
<h1>Introspect demo</h1>
|
||||
<h2>Query server for available methods and their description</h2>
|
||||
<h3>The code demonstrates usage of multicall and introspection methods</h3>
|
||||
<?php
|
||||
|
||||
include_once __DIR__ . "/../../src/Autoloader.php";
|
||||
PhpXmlRpc\Autoloader::register();
|
||||
|
||||
function display_error($r)
|
||||
{
|
||||
print "An error occurred: ";
|
||||
print "Code: " . $r->faultCode()
|
||||
. " Reason: '" . $r->faultString() . "'<br/>";
|
||||
}
|
||||
|
||||
$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 "<h3>methods available at http://" . $client->server . $client->path . "</h3>\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 "<h4>" . $methodName->scalarval() . "</h4>\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 "<h4>Documentation</h4><p>${txt}</p>\n";
|
||||
} else {
|
||||
print "<p>No documentation available.</p>\n";
|
||||
}
|
||||
}
|
||||
if ($rs[1]->faultCode()) {
|
||||
display_error($rs[1]);
|
||||
} else {
|
||||
print "<h4>Signature</h4><p>\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 "<code>" . $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 ")</code><br/>\n";
|
||||
}
|
||||
} else {
|
||||
print "Signature unknown\n";
|
||||
}
|
||||
print "</p>\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
</body>
|
||||
</html>
|
||||
66
lib/phpxmlrpc/demo/client/mail.php
Normal file
66
lib/phpxmlrpc/demo/client/mail.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
// Allow users to see the source of this file even if PHP is not configured for it
|
||||
if (isset($_GET['showSource']) && $_GET['showSource']) {
|
||||
highlight_file(__FILE__);
|
||||
die();
|
||||
}
|
||||
?>
|
||||
<html>
|
||||
<head><title>xmlrpc - Mail demo</title></head>
|
||||
<body>
|
||||
<h1>Mail demo</h1>
|
||||
|
||||
<p>This form enables you to send mail via an XML-RPC server.
|
||||
When you press <kbd>Send</kbd> this page will reload, showing you the XML-RPC request sent to the host server, the
|
||||
XML-RPC response received and the internal evaluation done by the PHP implementation.</p>
|
||||
|
||||
<p>You can find the source to this page here: <a href="mail.php?showSource=1">mail.php</a><br/>
|
||||
And the source to a functionally identical mail-by-XML-RPC server in the file <a
|
||||
href="../server/server.php?showSource=1">server.php</a> included with the library (look for the 'mail_send'
|
||||
method)</p>
|
||||
<?php
|
||||
|
||||
include_once __DIR__ . "/../../src/Autoloader.php";
|
||||
PhpXmlRpc\Autoloader::register();
|
||||
|
||||
if (isset($_POST["mailto"]) && $_POST["mailto"]) {
|
||||
$server = "http://phpxmlrpc.sourceforge.net/server.php";
|
||||
$req = new PhpXmlRpc\Request('mail.send', array(
|
||||
new PhpXmlRpc\Value($_POST["mailto"]),
|
||||
new PhpXmlRpc\Value($_POST["mailsub"]),
|
||||
new PhpXmlRpc\Value($_POST["mailmsg"]),
|
||||
new PhpXmlRpc\Value($_POST["mailfrom"]),
|
||||
new PhpXmlRpc\Value($_POST["mailcc"]),
|
||||
new PhpXmlRpc\Value($_POST["mailbcc"]),
|
||||
new PhpXmlRpc\Value("text/plain")
|
||||
));
|
||||
|
||||
$client = new PhpXmlRpc\Client($server);
|
||||
$client->setDebug(2);
|
||||
$resp = $client->send($req);
|
||||
if (!$resp->faultCode()) {
|
||||
print "Mail sent OK<br/>\n";
|
||||
} else {
|
||||
print "<fonr color=\"red\">";
|
||||
print "Mail send failed<br/>\n";
|
||||
print "Fault: ";
|
||||
print "Code: " . htmlspecialchars($resp->faultCode()) .
|
||||
" Reason: '" . htmlspecialchars($resp->faultString()) . "'<br/>";
|
||||
print "</font><br/>";
|
||||
}
|
||||
}
|
||||
?>
|
||||
<form method="POST">
|
||||
From <input size="60" name="mailfrom" value=""/><br/>
|
||||
<hr/>
|
||||
To <input size="60" name="mailto" value=""/><br/>
|
||||
Cc <input size="60" name="mailcc" value=""/><br/>
|
||||
Bcc <input size="60" name="mailbcc" value=""/><br/>
|
||||
<hr/>
|
||||
Subject <input size="60" name="mailsub" value="A message from xmlrpc"/>
|
||||
<hr/>
|
||||
Body <textarea rows="7" cols="60" name="mailmsg">Your message here</textarea><br/>
|
||||
<input type="Submit" value="Send"/>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
60
lib/phpxmlrpc/demo/client/proxy.php
Normal file
60
lib/phpxmlrpc/demo/client/proxy.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<html>
|
||||
<head><title>xmlrpc - Proxy demo</title></head>
|
||||
<body>
|
||||
<h1>proxy demo</h1>
|
||||
<h2>Query server using a 'proxy' object</h2>
|
||||
<h3>The code demonstrates usage for the terminally lazy. For a more complete proxy, look at at the Wrapper class</h3>
|
||||
<?php
|
||||
|
||||
include_once __DIR__ . "/../../src/Autoloader.php";
|
||||
PhpXmlRpc\Autoloader::register();
|
||||
|
||||
class PhpXmlRpcProxy
|
||||
{
|
||||
protected $client;
|
||||
protected $prefix = 'examples.';
|
||||
|
||||
public function __construct(PhpXmlRpc\Client $client)
|
||||
{
|
||||
$this->client = $client;
|
||||
}
|
||||
|
||||
/**
|
||||
* Translates any method call to an xmlrpc call.
|
||||
*
|
||||
* @author Toth Istvan
|
||||
*
|
||||
* @param string $name remote function name. Will be prefixed
|
||||
* @param array $arguments
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
function __call($name, $arguments)
|
||||
{
|
||||
$encoder = new PhpXmlRpc\Encoder();
|
||||
$valueArray = array();
|
||||
foreach ($arguments as $parameter) {
|
||||
$valueArray[] = $encoder->encode($parameter);
|
||||
}
|
||||
|
||||
// just in case this was set to something else
|
||||
$this->client->return_type = 'phpvals';
|
||||
|
||||
$resp = $this->client->send(new PhpXmlRpc\Request($this->prefix.$name, $valueArray));
|
||||
|
||||
if ($resp->faultCode()) {
|
||||
throw new Exception($resp->faultString(), $resp->faultCode());
|
||||
} else {
|
||||
return $resp->value();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$stateNo = rand(1, 51);
|
||||
$proxy = new PhpXmlRpcProxy(new \PhpXmlRpc\Client('http://phpxmlrpc.sourceforge.net/server.php'));
|
||||
$stateName = $proxy->getStateName($stateNo);
|
||||
|
||||
echo "State $stateNo is ".htmlspecialchars($stateName);
|
||||
30
lib/phpxmlrpc/demo/client/which.php
Normal file
30
lib/phpxmlrpc/demo/client/which.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<html>
|
||||
<head><title>xmlrpc - Which toolkit demo</title></head>
|
||||
<body>
|
||||
<h1>Which toolkit demo</h1>
|
||||
<h2>Query server for toolkit information</h2>
|
||||
<h3>The code demonstrates usage of the PhpXmlRpc\Encoder class</h3>
|
||||
<?php
|
||||
|
||||
include_once __DIR__ . "/../../src/Autoloader.php";
|
||||
PhpXmlRpc\Autoloader::register();
|
||||
|
||||
$req = new PhpXmlRpc\Request('interopEchoTests.whichToolkit', array());
|
||||
$client = new PhpXmlRpc\Client("http://phpxmlrpc.sourceforge.net/server.php");
|
||||
$resp = $client->send($req);
|
||||
if (!$resp->faultCode()) {
|
||||
$encoder = new PhpXmlRpc\Encoder();
|
||||
$value = $encoder->decode($resp->value());
|
||||
print "<pre>";
|
||||
print "name: " . htmlspecialchars($value["toolkitName"]) . "\n";
|
||||
print "version: " . htmlspecialchars($value["toolkitVersion"]) . "\n";
|
||||
print "docs: " . htmlspecialchars($value["toolkitDocsUrl"]) . "\n";
|
||||
print "os: " . htmlspecialchars($value["toolkitOperatingSystem"]) . "\n";
|
||||
print "</pre>";
|
||||
} else {
|
||||
print "An error occurred: ";
|
||||
print "Code: " . htmlspecialchars($resp->faultCode()) . " Reason: '" . htmlspecialchars($resp->faultString()) . "'\n";
|
||||
}
|
||||
?>
|
||||
</body>
|
||||
</html>
|
||||
53
lib/phpxmlrpc/demo/client/wrap.php
Normal file
53
lib/phpxmlrpc/demo/client/wrap.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<html>
|
||||
<head><title>xmlrpc - Webservice wrappper demo</title></head>
|
||||
<body>
|
||||
<h1>Webservice wrappper demo</h1>
|
||||
|
||||
<h2>Wrap methods exposed by server into php functions</h2>
|
||||
|
||||
<h3>The code demonstrates usage of some the most automagic client usage possible:<br/>
|
||||
1) client that returns php values instead of xmlrpc value objects<br/>
|
||||
2) wrapping of remote methods into php functions<br/>
|
||||
See also proxy.php for an alternative take
|
||||
</h3>
|
||||
<?php
|
||||
|
||||
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 "<p>Server methods list could not be retrieved: error {$resp->faultCode()} '" . htmlspecialchars($resp->faultString()) . "'</p>\n";
|
||||
} else {
|
||||
echo "<p>Server methods list retrieved, now wrapping it up...</p>\n<ul>\n";
|
||||
flush();
|
||||
|
||||
$callable = false;
|
||||
$wrapper = new PhpXmlRpc\Wrapper();
|
||||
foreach ($resp->value() as $methodName) {
|
||||
// $resp->value is an array of strings
|
||||
if ($methodName == 'examples.getStateName') {
|
||||
$callable = $wrapper->wrapXmlrpcMethod($client, $methodName);
|
||||
if ($callable) {
|
||||
echo "<li>Remote server method " . htmlspecialchars($methodName) . " wrapped into php function</li>\n";
|
||||
} else {
|
||||
echo "<li>Remote server method " . htmlspecialchars($methodName) . " could not be wrapped!</li>\n";
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
echo "</ul>\n";
|
||||
flush();
|
||||
|
||||
if ($callable) {
|
||||
echo "Now testing function for remote method to convert U.S. state number into state name";
|
||||
$stateNum = rand(1, 51);
|
||||
// the 2nd parameter gets added to the closure - it is teh debug level to be used for the client
|
||||
$stateName = $callable($stateNum, 2);
|
||||
}
|
||||
}
|
||||
?>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user