1 | <?php |
||
2 | require_once __DIR__ . "/client/_prepend.php"; |
||
3 | |||
4 | 1 | output('<html lang="en"> |
|
5 | <head><title>phpxmlrpc</title></head> |
||
6 | <body> |
||
7 | '); |
||
8 | |||
9 | 1 | output("<h3>Testing value serialization</h3>\n"); |
|
10 | output("<p>Please note that in most cases you are better off using `new PhpXmlRpc\Encoder()->encode()` to create nested Value objects</p>\n"); |
||
11 | 1 | ||
12 | $v = new PhpXmlRpc\Value(1234, 'int'); |
||
13 | 1 | output("Int: <PRE>" . htmlentities($v->serialize()) . "</PRE>"); |
|
14 | 1 | ||
15 | 1 | $v = new PhpXmlRpc\Value('Are the following characters escaped? < & >'); |
|
16 | 1 | output("String <PRE>" . htmlentities($v->serialize()) . "</PRE>"); |
|
17 | |||
18 | 1 | $v = new PhpXmlRpc\Value(true, 'boolean'); |
|
19 | output("Boolean: <PRE>" . htmlentities($v->serialize()) . "</PRE>"); |
||
20 | 1 | ||
21 | 1 | $v = new PhpXmlRpc\Value(1234.5678, 'double'); |
|
22 | 1 | output("Double: <PRE>" . htmlentities($v->serialize()) . "</PRE>"); |
|
23 | |||
24 | 1 | $v = new PhpXmlRpc\Value(time(), 'dateTime.iso8601'); |
|
25 | output("Datetime (from timestamp): <PRE>" . htmlentities($v->serialize()) . "</PRE>"); |
||
26 | $v = new PhpXmlRpc\Value(new DateTime(), 'dateTime.iso8601'); |
||
27 | 1 | output("Datetime (from php DateTime): <PRE>" . htmlentities($v->serialize()) . "</PRE>"); |
|
28 | |||
29 | 1 | $v = new PhpXmlRpc\Value('hello world', 'base64'); |
|
30 | output("Base64: <PRE>" . htmlentities($v->serialize()) . "</PRE>"); |
||
31 | 1 | output("(value of base64 string is: '" . $v->scalarVal() . "')<BR><BR>"); |
|
32 | |||
33 | 1 | $v = new PhpXmlRpc\Value( |
|
34 | 1 | array( |
|
35 | 1 | new PhpXmlRpc\Value('1234', 'i4'), |
|
36 | 1 | new PhpXmlRpc\Value("Can you spot the greek letter beta? β", 'string'), |
|
37 | 1 | new PhpXmlRpc\Value(1, 'boolean'), |
|
38 | 1 | new PhpXmlRpc\Value(1234, 'double'), |
|
39 | new PhpXmlRpc\Value(new DateTime(), 'dateTime.iso8601'), |
||
40 | 1 | new PhpXmlRpc\Value('', 'base64'), |
|
41 | ), |
||
42 | 1 | "array" |
|
43 | 1 | ); |
|
44 | 1 | output("Array: <PRE>" . htmlentities($v->serialize()) . "</PRE>"); |
|
45 | |||
46 | 1 | $v = new PhpXmlRpc\Value( |
|
47 | 1 | array( |
|
48 | "anInt" => new PhpXmlRpc\Value(23, 'int'), |
||
49 | 1 | "aString" => new PhpXmlRpc\Value('foobarwhizz'), |
|
50 | "anEmptyArray" => new PhpXmlRpc\Value( |
||
51 | array(), |
||
52 | 1 | "array" |
|
53 | ), |
||
54 | "aNestedStruct" => new PhpXmlRpc\Value( |
||
55 | 1 | array( |
|
56 | "one" => new PhpXmlRpc\Value(1, 'int'), |
||
57 | 1 | "two" => new PhpXmlRpc\Value(2, 'int'), |
|
58 | ), |
||
59 | 1 | "struct" |
|
60 | ), |
||
61 | 1 | ), |
|
62 | "struct" |
||
63 | ); |
||
64 | output("Struct: <PRE>" . htmlentities($v->serialize()) . "</PRE>"); |
||
65 | |||
66 | $w = new PhpXmlRpc\Value(array($v), 'array'); |
||
67 | output("Array containing a struct: <PRE>" . htmlentities($w->serialize()) . "</PRE>"); |
||
68 | |||
69 | 1 | class MyClass |
|
70 | { |
||
71 | 1 | public $public = 'a public property'; |
|
72 | 1 | protected $protected = 'a protected one'; |
|
73 | private $private = 'a private one'; |
||
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
74 | 1 | } |
|
75 | 1 | $myObject = new MyClass(); |
|
76 | // the public property is the only one which will be serialized. As such, it has to be of type Value |
||
77 | 1 | $myObject->public = new \PhpXmlRpc\Value('a public property, wrapped'); |
|
78 | 1 | $w = new PhpXmlRpc\Value($myObject, 'struct'); |
|
79 | 1 | output("Struct encoding a php object: <PRE>" . htmlentities($w->serialize()) . "</PRE>"); |
|
80 | |||
81 | 1 | output("<h3>Testing value serialization - xml-rpc extensions</h3>\n"); |
|
82 | $v = new PhpXmlRpc\Value(1234, 'i8'); |
||
83 | 1 | output("I8: <PRE>" . htmlentities($v->serialize()) . "</PRE>"); |
|
84 | 1 | $v = new PhpXmlRpc\Value(null, 'null'); |
|
85 | 1 | output("Null: <PRE>" . htmlentities($v->serialize()) . "</PRE>"); |
|
86 | 1 | \PhpXmlRpc\PhpXmlRpc::$xmlrpc_null_apache_encoding = true; |
|
87 | 1 | output("Null, alternative: <PRE>" . htmlentities($v->serialize()) . "</PRE>"); |
|
88 | 1 | ||
89 | 1 | output("<h3>Testing value serialization - character encoding</h3>\n"); |
|
90 | 1 | // The greek word 'kosme' |
|
91 | $v = new PhpXmlRpc\Value('κόσμε'); |
||
92 | 1 | output("Greek (default encoding): <PRE>" . htmlentities($v->serialize()) . "</PRE>"); |
|
93 | output("Greek (utf8 encoding): <PRE>" . htmlentities($v->serialize('UTF-8')) . "</PRE>"); |
||
94 | 1 | if (function_exists('mb_convert_encoding')) { |
|
95 | output("Greek (ISO-8859-7 encoding): <PRE>" . htmlentities($v->serialize('ISO-8859-7')) . "</PRE>"); |
||
96 | 1 | } |
|
97 | |||
98 | output("<h3>Testing request serialization</h3>\n"); |
||
99 | $req = new PhpXmlRpc\Request('examples.getStateName'); |
||
100 | $req->method('examples.getStateName'); |
||
101 | $req->addParam(new PhpXmlRpc\Value(42, 'int')); |
||
102 | output("<PRE>" . htmlentities($req->serialize()) . "</PRE>"); |
||
103 | |||
104 | output("<h3>Testing response serialization</h3>\n"); |
||
105 | $resp = new PhpXmlRpc\Response(new PhpXmlRpc\Value('The meaning of life')); |
||
106 | output("<PRE>" . htmlentities($resp->serialize()) . "</PRE>"); |
||
107 | |||
108 | output("<h3>Testing ISO date formatting</h3><pre>\n"); |
||
109 | $t = time(); |
||
110 | $date = PhpXmlRpc\Helper\Date::iso8601Encode($t); |
||
111 | output("Now is $t --> $date\n"); |
||
112 | output("Or in UTC, that is " . PhpXmlRpc\Helper\Date::iso8601Encode($t, 1) . "\n"); |
||
113 | $tb = PhpXmlRpc\Helper\Date::iso8601Decode($date); |
||
114 | output("That is to say $date --> $tb\n"); |
||
115 | output("Which comes out at " . PhpXmlRpc\Helper\Date::iso8601Encode($tb) . "\n"); |
||
116 | output("Which was the time in UTC at " . PhpXmlRpc\Helper\Date::iso8601Encode($tb, 1) . "\n"); |
||
117 | output("</pre>\n"); |
||
118 | |||
119 | output("<h3>Testing reduced-precision formatting for doubles</h3><pre>\n"); |
||
120 | $v = new PhpXmlRpc\Value(1234.56789, 'double'); |
||
121 | \PhpXmlRpc\PhpXmlRpc::$xmlpc_double_precision = 2; |
||
122 | output("Double, limited precision: <PRE>" . htmlentities($v->serialize()) . "</PRE>"); |
||
123 | |||
124 | output('</body></html>'); |
||
125 |