Refactor the Wrapper class to generate closures by default and avoid usage of 'eval'
[plcapi.git] / demo / client / client.php
index 755729d..06a256a 100644 (file)
@@ -1,5 +1,5 @@
 <html>
-<head><title>xmlrpc</title></head>
+<head><title>xmlrpc - Getstatename demo</title></head>
 <body>
 <h1>Getstatename demo</h1>
 
@@ -7,26 +7,24 @@
 
 <h3>The code demonstrates usage of the php_xmlrpc_encode function</h3>
 <?php
-include "xmlrpc.inc";
 
-// Play nice to PHP 5 installations with REGISTER_LONG_ARRAYS off
-if (!isset($HTTP_POST_VARS) && isset($_POST)) {
-    $HTTP_POST_VARS = $_POST;
-}
+include_once __DIR__ . "/../../src/Autoloader.php";
+PhpXmlRpc\Autoloader::register();
 
-if (isset($HTTP_POST_VARS["stateno"]) && $HTTP_POST_VARS["stateno"] != "") {
-    $stateno = (integer)$HTTP_POST_VARS["stateno"];
-    $f = new xmlrpcmsg('examples.getStateName',
-        array(php_xmlrpc_encode($stateno))
+if (isset($_POST["stateno"]) && $_POST["stateno"] != "") {
+    $stateNo = (integer)$_POST["stateno"];
+    $encoder = new PhpXmlRpc\Encoder();
+    $req = new PhpXmlRpc\Request('examples.getStateName',
+        array($encoder->encode($stateNo))
     );
-    print "<pre>Sending the following request:\n\n" . htmlentities($f->serialize()) . "\n\nDebug info of server data follows...\n\n";
-    $c = new xmlrpc_client("/server.php", "phpxmlrpc.sourceforge.net", 80);
-    $c->setDebug(1);
-    $r = &$c->send($f);
+    print "Sending the following request:<pre>\n\n" . htmlentities($req->serialize()) . "\n\n</pre>Debug info of server data follows...\n\n";
+    $client = new PhpXmlRpc\Client("http://phpxmlrpc.sourceforge.net/server.php");
+    $client->setDebug(1);
+    $r = $client->send($req);
     if (!$r->faultCode()) {
         $v = $r->value();
-        print "</pre><br/>State number " . $stateno . " is "
-            . htmlspecialchars($v->scalarval()) . "<br/>";
+        print "<br/>State number <b>" . $stateNo . "</b> is <b>"
+            . htmlspecialchars($v->scalarval()) . "</b><br/>";
         // print "<HR>I got this value back<BR><PRE>" .
         //  htmlentities($r->serialize()). "</PRE><HR>\n";
     } else {
@@ -35,11 +33,11 @@ if (isset($HTTP_POST_VARS["stateno"]) && $HTTP_POST_VARS["stateno"] != "") {
             . " Reason: '" . htmlspecialchars($r->faultString()) . "'</pre><br/>";
     }
 } else {
-    $stateno = "";
+    $stateNo = "";
 }
 
 print "<form action=\"client.php\" method=\"POST\">
-<input name=\"stateno\" value=\"" . $stateno . "\"><input type=\"submit\" value=\"go\" name=\"submit\"></form>
+<input name=\"stateno\" value=\"" . $stateNo . "\"><input type=\"submit\" value=\"go\" name=\"submit\"></form>
 <p>Enter a state number to query its name</p>";
 
 ?>