Move api docs to phpdoc (wip); fix wrong property name in Response class
[plcapi.git] / demo / vardemo.php
1 <html>
2 <head><title>xmlrpc</title></head>
3 <body>
4 <?php
5
6 include_once __DIR__ . "/../vendor/autoload.php";
7
8 $req = new PhpXmlRpc\Request('examples.getStateName');
9
10 print "<h3>Testing value serialization</h3>\n";
11
12 $v = new PhpXmlRpc\Value(23, "int");
13 print "<PRE>" . htmlentities($v->serialize()) . "</PRE>";
14 $v = new PhpXmlRpc\Value("What are you saying? >> << &&");
15 print "<PRE>" . htmlentities($v->serialize()) . "</PRE>";
16
17 $v = new PhpXmlRpc\Value(
18     array(
19         new PhpXmlRpc\Value("ABCDEFHIJ"),
20         new PhpXmlRpc\Value(1234, 'int'),
21         new PhpXmlRpc\Value(1, 'boolean'),
22     ),
23     "array"
24 );
25
26 print "<PRE>" . htmlentities($v->serialize()) . "</PRE>";
27
28 $v = new PhpXmlRpc\Value(
29     array(
30         "thearray" => new PhpXmlRpc\Value(
31             array(
32                 new PhpXmlRpc\Value("ABCDEFHIJ"),
33                 new PhpXmlRpc\Value(1234, 'int'),
34                 new PhpXmlRpc\Value(1, 'boolean'),
35                 new PhpXmlRpc\Value(0, 'boolean'),
36                 new PhpXmlRpc\Value(true, 'boolean'),
37                 new PhpXmlRpc\Value(false, 'boolean'),
38             ),
39             "array"
40         ),
41         "theint" => new PhpXmlRpc\Value(23, 'int'),
42         "thestring" => new PhpXmlRpc\Value("foobarwhizz"),
43         "thestruct" => new PhpXmlRpc\Value(
44             array(
45                 "one" => new PhpXmlRpc\Value(1, 'int'),
46                 "two" => new PhpXmlRpc\Value(2, 'int'),
47             ),
48             "struct"
49         ),
50     ),
51     "struct"
52 );
53
54 print "<PRE>" . htmlentities($v->serialize()) . "</PRE>";
55
56 $w = new PhpXmlRpc\Value(array($v, new PhpXmlRpc\Value("That was the struct!")), "array");
57
58 print "<PRE>" . htmlentities($w->serialize()) . "</PRE>";
59
60 $w = new PhpXmlRpc\Value("Mary had a little lamb,
61 Whose fleece was white as snow,
62 And everywhere that Mary went
63 the lamb was sure to go.
64
65 Mary had a little lamb
66 She tied it to a pylon
67 Ten thousand volts went down its back
68 And turned it into nylon", "base64"
69 );
70 print "<PRE>" . htmlentities($w->serialize()) . "</PRE>";
71 print "<PRE>Value of base64 string is: '" . $w->scalarval() . "'</PRE>";
72
73 $req->method('');
74 $req->addParam(new PhpXmlRpc\Value("41", "int"));
75
76 print "<h3>Testing request serialization</h3>\n";
77 $op = $req->serialize();
78 print "<PRE>" . htmlentities($op) . "</PRE>";
79
80 print "<h3>Testing ISO date format</h3><pre>\n";
81
82 $t = time();
83 $date = PhpXmlRpc\Helper\Date::iso8601Encode($t);
84 print "Now is $t --> $date\n";
85 print "Or in UTC, that is " . PhpXmlRpc\Helper\Date::iso8601Encode($t, 1) . "\n";
86 $tb = PhpXmlRpc\Helper\Date::iso8601Decode($date);
87 print "That is to say $date --> $tb\n";
88 print "Which comes out at " . PhpXmlRpc\Helper\Date::iso8601Encode($tb) . "\n";
89 print "Which was the time in UTC at " . PhpXmlRpc\Helper\Date::iso8601Encode($date, 1) . "\n";
90
91 print "</pre>\n";
92
93 ?>
94 </body>
95 </html>