Exemplo n.º 1
0
<body>
<?php 
include_once __DIR__ . "/../vendor/autoload.php";
$req = new PhpXmlRpc\Request('examples.getStateName');
print "<h3>Testing value serialization</h3>\n";
$v = new PhpXmlRpc\Value(23, "int");
print "<PRE>" . htmlentities($v->serialize()) . "</PRE>";
$v = new PhpXmlRpc\Value("What are you saying? >> << &&");
print "<PRE>" . htmlentities($v->serialize()) . "</PRE>";
$v = new PhpXmlRpc\Value(array(new PhpXmlRpc\Value("ABCDEFHIJ"), new PhpXmlRpc\Value(1234, 'int'), new PhpXmlRpc\Value(1, 'boolean')), "array");
print "<PRE>" . htmlentities($v->serialize()) . "</PRE>";
$v = new PhpXmlRpc\Value(array("thearray" => new PhpXmlRpc\Value(array(new PhpXmlRpc\Value("ABCDEFHIJ"), new PhpXmlRpc\Value(1234, 'int'), new PhpXmlRpc\Value(1, 'boolean'), new PhpXmlRpc\Value(0, 'boolean'), new PhpXmlRpc\Value(true, 'boolean'), new PhpXmlRpc\Value(false, 'boolean')), "array"), "theint" => new PhpXmlRpc\Value(23, 'int'), "thestring" => new PhpXmlRpc\Value("foobarwhizz"), "thestruct" => new PhpXmlRpc\Value(array("one" => new PhpXmlRpc\Value(1, 'int'), "two" => new PhpXmlRpc\Value(2, 'int')), "struct")), "struct");
print "<PRE>" . htmlentities($v->serialize()) . "</PRE>";
$w = new PhpXmlRpc\Value(array($v, new PhpXmlRpc\Value("That was the struct!")), "array");
print "<PRE>" . htmlentities($w->serialize()) . "</PRE>";
$w = new PhpXmlRpc\Value("Mary had a little lamb,\nWhose fleece was white as snow,\nAnd everywhere that Mary went\nthe lamb was sure to go.\n\nMary had a little lamb\nShe tied it to a pylon\nTen thousand volts went down its back\nAnd turned it into nylon", "base64");
print "<PRE>" . htmlentities($w->serialize()) . "</PRE>";
print "<PRE>Value of base64 string is: '" . $w->scalarval() . "'</PRE>";
$req->method('');
$req->addParam(new PhpXmlRpc\Value("41", "int"));
print "<h3>Testing request serialization</h3>\n";
$op = $req->serialize();
print "<PRE>" . htmlentities($op) . "</PRE>";
print "<h3>Testing ISO date format</h3><pre>\n";
$t = time();
$date = PhpXmlRpc\Helper\Date::iso8601Encode($t);
print "Now is {$t} --> {$date}\n";
print "Or in UTC, that is " . PhpXmlRpc\Helper\Date::iso8601Encode($t, 1) . "\n";
$tb = PhpXmlRpc\Helper\Date::iso8601Decode($date);
print "That is to say {$date} --> {$tb}\n";
print "Which comes out at " . PhpXmlRpc\Helper\Date::iso8601Encode($tb) . "\n";
Exemplo n.º 2
0
<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"];