serialize() public method

public serialize ( )
コード例 #1
0
ファイル: agesort.php プロジェクト: 5haman/knowledgetree
<?php 
include "xmlrpc.inc";
$inAr = array("Dave" => 24, "Edd" => 45, "Joe" => 37, "Fred" => 27);
reset($inAr);
print "This is the input data:<br/><pre>";
while (list($key, $val) = each($inAr)) {
    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 xmlrpcval(array("name" => new xmlrpcval($key), "age" => new xmlrpcval($val, "int")), "struct");
}
$v = new xmlrpcval($p, "array");
print "Encoded into xmlrpc format it looks like this: <pre>\n" . htmlentities($v->serialize()) . "</pre>\n";
// create client and message objects
$f = new xmlrpcmsg('examples.sortByAge', array($v));
$c = new xmlrpc_client("/server.php", "phpxmlrpc.sourceforge.net", 80);
// set maximum debug level, to have the complete communication printed to screen
$c->setDebug(2);
// send request
print "Now sending request (detailed debug info follows)";
$r =& $c->send($f);
// check response for errors, and take appropriate action
if (!$r->faultCode()) {
    print "The server gave me these results:<pre>";
    $v = $r->value();
    $max = $v->arraysize();
    for ($i = 0; $i < $max; $i++) {
        $rec = $v->arraymem($i);
コード例 #2
0
ファイル: vardemo.php プロジェクト: 5haman/knowledgetree
<?php 
include "xmlrpc.inc";
$f = new xmlrpcmsg('examples.getStateName');
print "<h3>Testing value serialization</h3>\n";
$v = new xmlrpcval(23, "int");
print "<PRE>" . htmlentities($v->serialize()) . "</PRE>";
$v = new xmlrpcval("What are you saying? >> << &&");
print "<PRE>" . htmlentities($v->serialize()) . "</PRE>";
$v = new xmlrpcval(array(new xmlrpcval("ABCDEFHIJ"), new xmlrpcval(1234, 'int'), new xmlrpcval(1, 'boolean')), "array");
print "<PRE>" . htmlentities($v->serialize()) . "</PRE>";
$v = new xmlrpcval(array("thearray" => new xmlrpcval(array(new xmlrpcval("ABCDEFHIJ"), new xmlrpcval(1234, 'int'), new xmlrpcval(1, 'boolean'), new xmlrpcval(0, 'boolean'), new xmlrpcval(true, 'boolean'), new xmlrpcval(false, 'boolean')), "array"), "theint" => new xmlrpcval(23, 'int'), "thestring" => new xmlrpcval("foobarwhizz"), "thestruct" => new xmlrpcval(array("one" => new xmlrpcval(1, 'int'), "two" => new xmlrpcval(2, 'int')), "struct")), "struct");
print "<PRE>" . htmlentities($v->serialize()) . "</PRE>";
$w = new xmlrpcval(array($v, new xmlrpcval("That was the struct!")), "array");
print "<PRE>" . htmlentities($w->serialize()) . "</PRE>";
$w = new xmlrpcval("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>";
$f->method('');
$f->addParam(new xmlrpcval("41", "int"));
print "<h3>Testing request serialization</h3>\n";
$op = $f->serialize();
print "<PRE>" . htmlentities($op) . "</PRE>";
print "<h3>Testing ISO date format</h3><pre>\n";
$t = time();
$date = iso8601_encode($t);
print "Now is {$t} --> {$date}\n";
print "Or in UTC, that is " . iso8601_encode($t, 1) . "\n";
$tb = iso8601_decode($date);
print "That is to say {$date} --> {$tb}\n";
print "Which comes out at " . iso8601_encode($tb) . "\n";
print "Which was the time in UTC at " . iso8601_decode($date, 1) . "\n";
コード例 #3
0
 function testStringInt()
 {
     $v = new xmlrpcval('hello world', 'int');
     $s = $v->serialize();
     $this->assertequals("<value><int>0</int></value>\n", $s);
 }
コード例 #4
0
ファイル: benchmark.php プロジェクト: ronaldodia/backend_al
            $values[] = new xmlrpcval($val[0], 'int');
            $values[] = new xmlrpcval($val[1], 'double');
            $values[] = new xmlrpcval($val[2], 'string');
            $values[] = new xmlrpcval($val[3], 'boolean');
            $values[] = new xmlrpcval($val[4], 'dateTime.iso8601');
            $values[] = new xmlrpcval($val[5], 'int');
            $values[] = new xmlrpcval($val[6], 'double');
            $values[] = new xmlrpcval($val[7], 'string');
            $values[] = new xmlrpcval($val[8], 'boolean');
            $values[] = new xmlrpcval($val[9], 'dateTime.iso8601');
            $valarray[$key] = new xmlrpcval($values, 'array');
        }
        $vals[] = new xmlrpcval($valarray, 'struct');
    }
    $value = new xmlrpcval($vals, 'array');
    $out = $value->serialize();
}
end_test('Data encoding (large array)', 'manual encoding', $out);
begin_test('Data encoding (large array)', 'automatic encoding');
for ($i = 0; $i < $num_tests; $i++) {
    $value = php_xmlrpc_encode($data, array('auto_dates'));
    $out = $value->serialize();
}
end_test('Data encoding (large array)', 'automatic encoding', $out);
if (function_exists('xmlrpc_set_type')) {
    begin_test('Data encoding (large array)', 'xmlrpc-epi encoding');
    for ($i = 0; $i < $num_tests; $i++) {
        for ($j = 0; $j < 10; $j++) {
            foreach ($keys as $k) {
                xmlrpc_set_type($data[$j][$k][4], 'datetime');
                xmlrpc_set_type($data[$j][$k][8], 'datetime');
コード例 #5
0
 public function testDateTime()
 {
     $time = time();
     $t1 = new xmlrpcval($time, 'dateTime.iso8601');
     $t2 = new xmlrpcval(iso8601_encode($time), 'dateTime.iso8601');
     $this->assertEquals($t1->serialize(), $t2->serialize());
     if (class_exists('DateTime')) {
         $datetime = new DateTime();
         // skip this test for php 5.2. It is a bit harder there to build a DateTime from unix timestamp with proper TZ info
         if (is_callable(array($datetime, 'setTimestamp'))) {
             $t3 = new xmlrpcval($datetime->setTimestamp($time), 'dateTime.iso8601');
             $this->assertEquals($t1->serialize(), $t3->serialize());
         }
     }
 }
コード例 #6
0
 function TestLocale()
 {
     $locale = setlocale(LC_NUMERIC, 0);
     /// @todo on php 5.3/win setting locale to german does not seem to set decimal separator to comma...
     if (setlocale(LC_NUMERIC, 'deu', 'de_DE@euro', 'de_DE', 'de', 'ge') !== false) {
         $v = new xmlrpcval(1.1, 'double');
         if (strpos($v->scalarval(), ',') == 1) {
             $r = $v->serialize();
             $this->assertequals(false, strpos($r, ','));
         }
         setlocale(LC_NUMERIC, $locale);
     }
 }
コード例 #7
0
 function TestLocale()
 {
     $locale = setlocale(LC_NUMERIC, 0);
     if (setlocale(LC_NUMERIC, 'deu', 'de_DE@euro', 'de_DE', 'de', 'ge') !== false) {
         $v = new xmlrpcval(1.1, 'double');
         $r = $v->serialize();
         $this->assertequals(false, strpos($r, ','));
         $this->assertequals(1, strpos($v->scalarval(), ','));
         setlocale(LC_NUMERIC, $locale);
     }
 }