improve demo files pI: remove useless files; vardemo.php
authorgggeek <giunta.gaetano@gmail.com>
Sat, 7 Jan 2023 21:26:44 +0000 (21:26 +0000)
committergggeek <giunta.gaetano@gmail.com>
Sat, 7 Jan 2023 21:26:44 +0000 (21:26 +0000)
demo/demo1.xml [deleted file]
demo/demo2.xml [deleted file]
demo/demo3.xml [deleted file]
demo/vardemo.php

diff --git a/demo/demo1.xml b/demo/demo1.xml
deleted file mode 100644 (file)
index eeb6a69..0000000
+++ /dev/null
@@ -1,60 +0,0 @@
-<?xml version="1.0"?>
-<methodResponse>
-    <params>
-        <param>
-            <value>
-                <struct>
-                    <member>
-                        <name>thearray</name>
-                        <value>
-                            <array>
-                                <data>
-                                    <value>
-                                        <string>ABCDEFHIJ</string>
-                                    </value>
-                                    <value>
-                                        <int>1234</int>
-                                    </value>
-                                    <value>
-                                        <boolean>1</boolean>
-                                    </value>
-                                </data>
-                            </array>
-                        </value>
-                    </member>
-                    <member>
-                        <name>theint</name>
-                        <value>
-                            <int>23</int>
-                        </value>
-                    </member>
-                    <member>
-                        <name>thestring</name>
-                        <value>
-                            <string>foobarwhizz</string>
-                        </value>
-                    </member>
-                    <member>
-                        <name>thestruct</name>
-                        <value>
-                            <struct>
-                                <member>
-                                    <name>one</name>
-                                    <value>
-                                        <int>1</int>
-                                    </value>
-                                </member>
-                                <member>
-                                    <name>two</name>
-                                    <value>
-                                        <int>2</int>
-                                    </value>
-                                </member>
-                            </struct>
-                        </value>
-                    </member>
-                </struct>
-            </value>
-        </param>
-    </params>
-</methodResponse>
diff --git a/demo/demo2.xml b/demo/demo2.xml
deleted file mode 100644 (file)
index 3289caf..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-<?xml version="1.0"?>
-<methodResponse>
-    <params>
-        <param>
-            <value>
-                <string>South Dakota's own</string>
-            </value>
-        </param>
-    </params>
-</methodResponse>
diff --git a/demo/demo3.xml b/demo/demo3.xml
deleted file mode 100644 (file)
index ed94aab..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-<?xml version="1.0"?>
-<methodResponse>
-    <fault>
-        <value>
-            <struct>
-                <member>
-                    <name>faultCode</name>
-                    <value>
-                        <int>4</int>
-                    </value>
-                </member>
-                <member>
-                    <name>faultString</name>
-                    <value>
-                        <string>Too many parameters.</string>
-                    </value>
-                </member>
-            </struct>
-        </value>
-    </fault>
-</methodResponse>
index ac7e678..be748f7 100644 (file)
@@ -1,47 +1,55 @@
 <?php
 require_once __DIR__ . "/client/_prepend.php";
 
-output('html lang="en">
+output('<html lang="en">
 <head><title>xmlrpc</title></head>
 <body>
 ');
 
-$req = new PhpXmlRpc\Request('examples.getStateName');
-
 output("<h3>Testing value serialization</h3>\n");
+output("<p>Please note that in most cases you are better off using `new PhpXmlRpc\Encoder()->encode()` to create nested Value objects</p>\n");
+
+$v = new PhpXmlRpc\Value(1234, 'int');
+output("Int: <PRE>" . htmlentities($v->serialize()) . "</PRE>");
+
+$v = new PhpXmlRpc\Value('Are the following characters escaped? < & >');
+output("String <PRE>" . htmlentities($v->serialize()) . "</PRE>");
 
-$v = new PhpXmlRpc\Value(23, "int");
-output("<PRE>" . htmlentities($v->serialize()) . "</PRE>");
-$v = new PhpXmlRpc\Value("What are you saying? >> << &&");
-output("<PRE>" . htmlentities($v->serialize()) . "</PRE>");
+$v = new PhpXmlRpc\Value(true, 'boolean');
+output("Boolean: <PRE>" . htmlentities($v->serialize()) . "</PRE>");
+
+$v = new PhpXmlRpc\Value(1234.5678, 'double');
+output("Double: <PRE>" . htmlentities($v->serialize()) . "</PRE>");
+
+$v = new PhpXmlRpc\Value(time(), 'dateTime.iso8601');
+output("Datetime: <PRE>" . htmlentities($v->serialize()) . "</PRE>");
+
+$v = new PhpXmlRpc\Value('hello world', 'base64');
+output("Base64: <PRE>" . htmlentities($v->serialize()) . "</PRE>");
+output("(value of base64 string is: '" . $v->scalarval() . "')<BR><BR>");
 
 $v = new PhpXmlRpc\Value(
     array(
-        new PhpXmlRpc\Value("ABCDEFHIJ"),
-        new PhpXmlRpc\Value(1234, 'int'),
+        new PhpXmlRpc\Value('1234', 'i4'),
+        new PhpXmlRpc\Value("Can you spot the greek letter beta? β", 'string'),
         new PhpXmlRpc\Value(1, 'boolean'),
+        new PhpXmlRpc\Value(1234, 'double'),
+        new PhpXmlRpc\Value(new DateTime(), 'dateTime.iso8601'),
+        new PhpXmlRpc\Value('', 'base64'),
     ),
     "array"
 );
-
-output("<PRE>" . htmlentities($v->serialize()) . "</PRE>");
+output("Array: <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'),
-            ),
+        "anInt" => new PhpXmlRpc\Value(23, 'int'),
+        "aString" => new PhpXmlRpc\Value('foobarwhizz'),
+        "anEmptyArray" => new PhpXmlRpc\Value(
+            array(),
             "array"
         ),
-        "theint" => new PhpXmlRpc\Value(23, 'int'),
-        "thestring" => new PhpXmlRpc\Value("foobarwhizz"),
-        "thestruct" => new PhpXmlRpc\Value(
+        "aNestedStruct" => new PhpXmlRpc\Value(
             array(
                 "one" => new PhpXmlRpc\Value(1, 'int'),
                 "two" => new PhpXmlRpc\Value(2, 'int'),
@@ -51,14 +59,12 @@ $v = new PhpXmlRpc\Value(
     ),
     "struct"
 );
+output("Struct: <PRE>" . htmlentities($v->serialize()) . "</PRE>");
 
-output("<PRE>" . htmlentities($v->serialize()) . "</PRE>");
-
-$w = new PhpXmlRpc\Value(array($v, new PhpXmlRpc\Value("That was the struct!")), "array");
-
-output("<PRE>" . htmlentities($w->serialize()) . "</PRE>");
+$w = new PhpXmlRpc\Value(array($v), 'array');
+output("Array containing a struct: <PRE>" . htmlentities($w->serialize()) . "</PRE>");
 
-$w = new PhpXmlRpc\Value("Mary had a little lamb,
+/*$w = new PhpXmlRpc\Value("Mary had a little lamb,
 Whose fleece was white as snow,
 And everywhere that Mary went
 the lamb was sure to go.
@@ -69,17 +75,19 @@ Ten thousand volts went down its back
 And turned it into nylon", "base64"
 );
 output("<PRE>" . htmlentities($w->serialize()) . "</PRE>");
-output("<PRE>Value of base64 string is: '" . $w->scalarval() . "'</PRE>");
-
-$req->method('');
-$req->addParam(new PhpXmlRpc\Value("41", "int"));
+output("<PRE>Value of base64 string is: '" . $w->scalarval() . "'</PRE>");*/
 
 output("<h3>Testing request serialization</h3>\n");
-$op = $req->serialize();
-output("<PRE>" . htmlentities($op) . "</PRE>");
+$req = new PhpXmlRpc\Request('examples.getStateName');
+$req->method('examples.getStateName');
+$req->addParam(new PhpXmlRpc\Value(42, 'int'));
+output("<PRE>" . htmlentities($req->serialize()) . "</PRE>");
 
-output("<h3>Testing ISO date format</h3><pre>\n");
+output("<h3>Testing response serialization</h3>\n");
+$resp = new PhpXmlRpc\Response(new PhpXmlRpc\Value('The meaning of life'));
+output("<PRE>" . htmlentities($resp->serialize()) . "</PRE>");
 
+output("<h3>Testing ISO date formatting</h3><pre>\n");
 $t = time();
 $date = PhpXmlRpc\Helper\Date::iso8601Encode($t);
 output("Now is $t --> $date\n");
@@ -88,7 +96,6 @@ $tb = PhpXmlRpc\Helper\Date::iso8601Decode($date);
 output("That is to say $date --> $tb\n");
 output("Which comes out at " . PhpXmlRpc\Helper\Date::iso8601Encode($tb) . "\n");
 output("Which was the time in UTC at " . PhpXmlRpc\Helper\Date::iso8601Encode($tb, 1) . "\n");
-
 output("</pre>\n");
 
 output('</body></html>');