Refactor demo server: do not rely any more on legacy, more CamelCasiness
authorgggeek <giunta.gaetano@gmail.com>
Fri, 17 Apr 2015 23:05:30 +0000 (00:05 +0100)
committergggeek <giunta.gaetano@gmail.com>
Fri, 17 Apr 2015 23:05:30 +0000 (00:05 +0100)
demo/server/server.php

index 35e2dc0..e6b4bb4 100644 (file)
@@ -28,45 +28,42 @@ if (isset($_COOKIE['PHPUNIT_SELENIUM_TEST_ID']) && extension_loaded('xdebug')) {
     include_once __DIR__ . "/../../vendor/phpunit/phpunit-selenium/PHPUnit/Extensions/SeleniumCommon/prepend.php";
 }
 
-include_once __DIR__ . "/../../lib/xmlrpc.inc";
-include_once __DIR__ . "/../../lib/xmlrpcs.inc";
-include_once __DIR__ . "/../../lib/xmlrpc_wrappers.inc";
+use PhpXmlRpc\Value;
 
 /**
  * Used to test usage of object methods in dispatch maps and in wrapper code.
  */
-class xmlrpc_server_methods_container
+class xmlrpcServerMethodsContainer
 {
     /**
      * Method used to test logging of php warnings generated by user functions.
      */
-    public function phpwarninggenerator($m)
+    public function phpWarningGenerator($m)
     {
         $a = $undefinedVariable; // this triggers a warning in E_ALL mode, since $undefinedVariable is undefined
-        return new PhpXmlRpc\Response(new PhpXmlRpc\Value(1, 'boolean'));
+        return new PhpXmlRpc\Response(new Value(1, 'boolean'));
     }
 
     /**
      * Method used to test catching of exceptions in the server.
      */
-    public function exceptiongenerator($m)
+    public function exceptionGenerator($m)
     {
         throw new Exception("it's just a test", 1);
     }
 
-    /*
-    * a PHP version of the state-number server. Send me an integer and i'll sell you a state
+    /**
+    * A PHP version of the state-number server. Send me an integer and i'll sell you a state
     * @param integer $s
     * @return string
     */
-    public static function findstate($s)
+    public static function findState($s)
     {
         return inner_findstate($s);
     }
 }
 
-// a PHP version
-// of the state-number server
+// a PHP version of the state-number server
 // send me an integer and i'll sell you a state
 
 $stateNames = array(
@@ -81,134 +78,129 @@ $stateNames = array(
     "Virginia", "Washington", "West Virginia", "Wisconsin", "Wyoming",
 );
 
-$findstate_sig = array(array($xmlrpcString, $xmlrpcInt));
+$findstate_sig = array(array(Value::$xmlrpcString, Value::$xmlrpcInt));
 $findstate_doc = 'When passed an integer between 1 and 51 returns the
 name of a US state, where the integer is the index of that state name
 in an alphabetic order.';
 
-function findstate($m)
+function findState($m)
 {
-    global $xmlrpcerruser, $stateNames;
+    global $stateNames;
     $err = "";
     // get the first param
     $sno = $m->getParam(0);
 
-    // param must be there and of the correct type: server object does the
-    // validation for us
+    // param must be there and of the correct type: server object does the validation for us
 
     // extract the value of the state number
     $snv = $sno->scalarval();
     // look it up in our array (zero-based)
     if (isset($stateNames[$snv - 1])) {
-        $sname = $stateNames[$snv - 1];
+        $stateName = $stateNames[$snv - 1];
     } else {
-        // not, there so complain
+        // not there, so complain
         $err = "I don't have a state for the index '" . $snv . "'";
     }
 
     // if we generated an error, create an error return response
     if ($err) {
-        return new PhpXmlRpc\Response(0, $xmlrpcerruser, $err);
+        return new PhpXmlRpc\Response(0, PhpXmlRpc\PhpXmlRpc::$xmlrpcerruser, $err);
     } else {
-        // otherwise, we create the right response
-        // with the state name
-        return new PhpXmlRpc\Response(new PhpXmlRpc\Value($sname));
+        // otherwise, we create the right response with the state name
+        return new PhpXmlRpc\Response(new Value($stateName));
     }
 }
 
 /**
  * Inner code of the state-number server.
- * Used to test auto-registration of PHP funcions as xmlrpc methods.
+ * Used to test auto-registration of PHP functions as xmlrpc methods.
  *
- * @param integer $stateno the state number
+ * @param integer $stateNo the state number
  *
- * @return string the name of the state (or error descrption)
+ * @return string the name of the state (or error description)
  */
-function inner_findstate($stateno)
+function inner_findstate($stateNo)
 {
     global $stateNames;
-    if (isset($stateNames[$stateno - 1])) {
-        return $stateNames[$stateno - 1];
+    if (isset($stateNames[$stateNo - 1])) {
+        return $stateNames[$stateNo - 1];
     } else {
         // not, there so complain
-        return "I don't have a state for the index '" . $stateno . "'";
+        return "I don't have a state for the index '" . $stateNo . "'";
     }
 }
 
-$findstate2_sig = wrap_php_function('inner_findstate');
+$wrapper = new PhpXmlRpc\Wrapper();
 
-$findstate3_sig = wrap_php_function(array('xmlrpc_server_methods_container', 'findstate'));
+$findstate2_sig = $wrapper->wrap_php_function('inner_findstate');
 
-$findstate5_sig = wrap_php_function('xmlrpc_server_methods_container::findstate');
+$findstate3_sig = $wrapper->wrap_php_function(array('xmlrpcServerMethodsContainer', 'findState'));
 
-$obj = new xmlrpc_server_methods_container();
-$findstate4_sig = wrap_php_function(array($obj, 'findstate'));
+$findstate5_sig = $wrapper->wrap_php_function('xmlrpcServerMethodsContainer::findState');
 
-$addtwo_sig = array(array($xmlrpcInt, $xmlrpcInt, $xmlrpcInt));
+$obj = new xmlrpcServerMethodsContainer();
+$findstate4_sig = $wrapper->wrap_php_function(array($obj, 'findstate'));
+
+$addtwo_sig = array(array(Value::$xmlrpcInt, Value::$xmlrpcInt, Value::$xmlrpcInt));
 $addtwo_doc = 'Add two integers together and return the result';
-function addtwo($m)
+function addTwo($m)
 {
     $s = $m->getParam(0);
     $t = $m->getParam(1);
 
-    return new PhpXmlRpc\Response(new PhpXmlRpc\Value($s->scalarval() + $t->scalarval(), "int"));
+    return new PhpXmlRpc\Response(new Value($s->scalarval() + $t->scalarval(), "int"));
 }
 
-$addtwodouble_sig = array(array($xmlrpcDouble, $xmlrpcDouble, $xmlrpcDouble));
+$addtwodouble_sig = array(array(Value::$xmlrpcDouble, Value::$xmlrpcDouble, Value::$xmlrpcDouble));
 $addtwodouble_doc = 'Add two doubles together and return the result';
-function addtwodouble($m)
+function addTwoDouble($m)
 {
     $s = $m->getParam(0);
     $t = $m->getParam(1);
 
-    return new PhpXmlRpc\Response(new PhpXmlRpc\Value($s->scalarval() + $t->scalarval(), "double"));
+    return new PhpXmlRpc\Response(new Value($s->scalarval() + $t->scalarval(), "double"));
 }
 
-$stringecho_sig = array(array($xmlrpcString, $xmlrpcString));
+$stringecho_sig = array(array(Value::$xmlrpcString, Value::$xmlrpcString));
 $stringecho_doc = 'Accepts a string parameter, returns the string.';
-function stringecho($m)
+function stringEcho($m)
 {
     // just sends back a string
     $s = $m->getParam(0);
     $v = $s->scalarval();
 
-    return new PhpXmlRpc\Response(new PhpXmlRpc\Value($s->scalarval()));
+    return new PhpXmlRpc\Response(new Value($s->scalarval()));
 }
 
-$echoback_sig = array(array($xmlrpcString, $xmlrpcString));
+$echoback_sig = array(array(Value::$xmlrpcString, Value::$xmlrpcString));
 $echoback_doc = 'Accepts a string parameter, returns the entire incoming payload';
-function echoback($m)
+function echoBack($m)
 {
-    // just sends back a string with what i got
-    // sent to me, just escaped, that's all
-    //
-    // $m is an incoming message
+    // just sends back a string with what i got sent to me, just escaped, that's all
     $s = "I got the following message:\n" . $m->serialize();
 
-    return new PhpXmlRpc\Response(new PhpXmlRpc\Value($s));
+    return new PhpXmlRpc\Response(new Value($s));
 }
 
-$echosixtyfour_sig = array(array($xmlrpcString, $xmlrpcBase64));
+$echosixtyfour_sig = array(array(Value::$xmlrpcString, Value::$xmlrpcBase64));
 $echosixtyfour_doc = 'Accepts a base64 parameter and returns it decoded as a string';
-function echosixtyfour($m)
+function echoSixtyFour($m)
 {
     // accepts an encoded value, but sends it back
     // as a normal string. this is to test base64 encoding
     // is working as expected
     $incoming = $m->getParam(0);
 
-    return new PhpXmlRpc\Response(new PhpXmlRpc\Value($incoming->scalarval(), "string"));
+    return new PhpXmlRpc\Response(new Value($incoming->scalarval(), "string"));
 }
 
-$bitflipper_sig = array(array($xmlrpcArray, $xmlrpcArray));
+$bitflipper_sig = array(array(Value::$xmlrpcArray, Value::$xmlrpcArray));
 $bitflipper_doc = 'Accepts an array of booleans, and returns them inverted';
-function bitflipper($m)
+function bitFlipper($m)
 {
-    global $xmlrpcArray;
-
     $v = $m->getParam(0);
     $sz = $v->arraysize();
-    $rv = new PhpXmlRpc\Value(array(), $xmlrpcArray);
+    $rv = new Value(array(), Value::$xmlrpcArray);
 
     for ($j = 0; $j < $sz; $j++) {
         $b = $v->arraymem($j);
@@ -237,8 +229,7 @@ function agesorter_compare($a, $b)
 {
     global $agesorter_arr;
 
-    // don't even ask me _why_ these come padded with
-    // hyphens, I couldn't tell you :p
+    // don't even ask me _why_ these come padded with hyphens, I couldn't tell you :p
     $a = str_replace("-", "", $a);
     $b = str_replace("-", "", $b);
 
@@ -249,7 +240,7 @@ function agesorter_compare($a, $b)
     return ($agesorter_arr[$a] > $agesorter_arr[$b]) ? -1 : 1;
 }
 
-$agesorter_sig = array(array($xmlrpcArray, $xmlrpcArray));
+$agesorter_sig = array(array(Value::$xmlrpcArray, Value::$xmlrpcArray));
 $agesorter_doc = 'Send this method an array of [string, int] structs, eg:
 <pre>
  Dave   35
@@ -259,55 +250,50 @@ $agesorter_doc = 'Send this method an array of [string, int] structs, eg:
 </pre>
 And the array will be returned with the entries sorted by their numbers.
 ';
-function agesorter($m)
+function ageSorter($m)
 {
-    global $agesorter_arr, $xmlrpcerruser, $s;
+    global $agesorter_arr, $s;
 
-    xmlrpc_debugmsg("Entering 'agesorter'");
+    PhpXmlRpc\Server::xmlrpc_debugmsg("Entering 'agesorter'");
     // get the parameter
     $sno = $m->getParam(0);
     // error string for [if|when] things go wrong
     $err = "";
     // create the output value
-    $v = new PhpXmlRpc\Value();
+    $v = new Value();
     $agar = array();
 
-    if (isset($sno) && $sno->kindOf() == "array") {
-        $max = $sno->arraysize();
-        // TODO: create debug method to print can work once more
-        // print "<!-- found $max array elements -->\n";
-        for ($i = 0; $i < $max; $i++) {
-            $rec = $sno->arraymem($i);
-            if ($rec->kindOf() != "struct") {
-                $err = "Found non-struct in array at element $i";
-                break;
-            }
-            // extract name and age from struct
-            $n = $rec->structmem("name");
-            $a = $rec->structmem("age");
-            // $n and $a are xmlrpcvals,
-            // so get the scalarval from them
-            $agar[$n->scalarval()] = $a->scalarval();
+    $max = $sno->arraysize();
+    PhpXmlRpc\Server::xmlrpc_debugmsg("Found $max array elements");
+    for ($i = 0; $i < $max; $i++) {
+        $rec = $sno->arraymem($i);
+        if ($rec->kindOf() != "struct") {
+            $err = "Found non-struct in array at element $i";
+            break;
         }
+        // extract name and age from struct
+        $n = $rec->structmem("name");
+        $a = $rec->structmem("age");
+        // $n and $a are xmlrpcvals,
+        // so get the scalarval from them
+        $agar[$n->scalarval()] = $a->scalarval();
+    }
 
-        $agesorter_arr = $agar;
-        // hack, must make global as uksort() won't
-        // allow us to pass any other auxilliary information
-        uksort($agesorter_arr, agesorter_compare);
-        $outAr = array();
-        while (list($key, $val) = each($agesorter_arr)) {
-            // recreate each struct element
-            $outAr[] = new PhpXmlRpc\Value(array("name" => new PhpXmlRpc\Value($key),
-                "age" => new PhpXmlRpc\Value($val, "int"),), "struct");
-        }
-        // add this array to the output value
-        $v->addArray($outAr);
-    } else {
-        $err = "Must be one parameter, an array of structs";
+    $agesorter_arr = $agar;
+    // hack, must make global as uksort() won't
+    // allow us to pass any other auxiliary information
+    uksort($agesorter_arr, 'agesorter_compare');
+    $outAr = array();
+    while (list($key, $val) = each($agesorter_arr)) {
+        // recreate each struct element
+        $outAr[] = new Value(array("name" => new Value($key),
+            "age" => new Value($val, "int"),), "struct");
     }
+    // add this array to the output value
+    $v->addArray($outAr);
 
     if ($err) {
-        return new PhpXmlRpc\Response(0, $xmlrpcerruser, $err);
+        return new PhpXmlRpc\Response(0, PhpXmlRpc\PhpXmlRpc::$xmlrpcerruser, $err);
     } else {
         return new PhpXmlRpc\Response($v);
     }
@@ -315,13 +301,13 @@ function agesorter($m)
 
 // signature and instructions, place these in the dispatch
 // map
-$mail_send_sig = array(array(
-    $xmlrpcBoolean, $xmlrpcString, $xmlrpcString,
-    $xmlrpcString, $xmlrpcString, $xmlrpcString,
-    $xmlrpcString, $xmlrpcString,
+$mailsend_sig = array(array(
+    Value::$xmlrpcBoolean, Value::$xmlrpcString, Value::$xmlrpcString,
+    Value::$xmlrpcString, Value::$xmlrpcString, Value::$xmlrpcString,
+    Value::$xmlrpcString, Value::$xmlrpcString,
 ));
 
-$mail_send_doc = 'mail.send(recipient, subject, text, sender, cc, bcc, mimetype)<br/>
+$mailsend_doc = 'mail.send(recipient, subject, text, sender, cc, bcc, mimetype)<br/>
 recipient, cc, and bcc are strings, comma-separated lists of email addresses, as described above.<br/>
 subject is a string, the subject of the message.<br/>
 sender is a string, it\'s the email address of the person sending the message. This string can not be
@@ -332,9 +318,8 @@ mimetype, a string, is a standard MIME type, for example, text/plain.
 // WARNING; this functionality depends on the sendmail -t option
 // it may not work with Windows machines properly; particularly
 // the Bcc option. Sneak on your friends at your own risk!
-function mail_send($m)
+function mailSend($m)
 {
-    global $xmlrpcerruser, $xmlrpcBoolean;
     $err = "";
 
     $mTo = $m->getParam(0);
@@ -378,19 +363,20 @@ function mail_send($m)
     }
 
     if ($err) {
-        return new PhpXmlRpc\Response(0, $xmlrpcerruser, $err);
+        return new PhpXmlRpc\Response(0, PhpXmlRpc\PhpXmlRpc::$xmlrpcerruser, $err);
     } else {
-        return new PhpXmlRpc\Response(new PhpXmlRpc\Value("true", $xmlrpcBoolean));
+        return new PhpXmlRpc\Response(new Value("true", Value::$xmlrpcBoolean));
     }
 }
 
-$getallheaders_sig = array(array($xmlrpcStruct));
+$getallheaders_sig = array(array(Value::$xmlrpcStruct));
 $getallheaders_doc = 'Returns a struct containing all the HTTP headers received with the request. Provides limited functionality with IIS';
 function getallheaders_xmlrpc($m)
 {
-    global $xmlrpcerruser;
+    $encoder = new PhpXmlRpc\Encoder();
+
     if (function_exists('getallheaders')) {
-        return new PhpXmlRpc\Response(php_xmlrpc_encode(getallheaders()));
+        return new PhpXmlRpc\Response($encoder->encode(getallheaders()));
     } else {
         $headers = array();
         // IIS: poor man's version of getallheaders
@@ -401,50 +387,52 @@ function getallheaders_xmlrpc($m)
             }
         }
 
-        return new PhpXmlRpc\Response(php_xmlrpc_encode($headers));
+        return new PhpXmlRpc\Response($encoder->encode($headers));
     }
 }
 
-$setcookies_sig = array(array($xmlrpcInt, $xmlrpcStruct));
+$setcookies_sig = array(array(Value::$xmlrpcInt, Value::$xmlrpcStruct));
 $setcookies_doc = 'Sends to client a response containing a single \'1\' digit, and sets to it http cookies as received in the request (array of structs describing a cookie)';
-function setcookies($m)
+function setCookies($m)
 {
+    $encoder = new PhpXmlRpc\Encoder();
     $m = $m->getParam(0);
     while (list($name, $value) = $m->structeach()) {
-        $cookiedesc = php_xmlrpc_decode($value);
-        setcookie($name, @$cookiedesc['value'], @$cookiedesc['expires'], @$cookiedesc['path'], @$cookiedesc['domain'], @$cookiedesc['secure']);
+        $cookieDesc = $encoder->decode($value);
+        setcookie($name, @$cookieDesc['value'], @$cookieDesc['expires'], @$cookieDesc['path'], @$cookieDesc['domain'], @$cookieDesc['secure']);
     }
 
-    return new PhpXmlRpc\Response(new PhpXmlRpc\Value(1, 'int'));
+    return new PhpXmlRpc\Response(new Value(1, 'int'));
 }
 
-$getcookies_sig = array(array($xmlrpcStruct));
+$getcookies_sig = array(array(Value::$xmlrpcStruct));
 $getcookies_doc = 'Sends to client a response containing all http cookies as received in the request (as struct)';
-function getcookies($m)
+function getCookies($m)
 {
-    return new PhpXmlRpc\Response(php_xmlrpc_encode($_COOKIE));
+    $encoder = new PhpXmlRpc\Encoder();
+    return new PhpXmlRpc\Response($encoder->encode($_COOKIE));
 }
 
-$v1_arrayOfStructs_sig = array(array($xmlrpcInt, $xmlrpcArray));
+$v1_arrayOfStructs_sig = array(array(Value::$xmlrpcInt, Value::$xmlrpcArray));
 $v1_arrayOfStructs_doc = 'This handler takes a single parameter, an array of structs, each of which contains at least three elements named moe, larry and curly, all <i4>s. Your handler must add all the struct elements named curly and return the result.';
 function v1_arrayOfStructs($m)
 {
     $sno = $m->getParam(0);
-    $numcurly = 0;
+    $numCurly = 0;
     for ($i = 0; $i < $sno->arraysize(); $i++) {
         $str = $sno->arraymem($i);
         $str->structreset();
         while (list($key, $val) = $str->structeach()) {
             if ($key == "curly") {
-                $numcurly += $val->scalarval();
+                $numCurly += $val->scalarval();
             }
         }
     }
 
-    return new PhpXmlRpc\Response(new PhpXmlRpc\Value($numcurly, "int"));
+    return new PhpXmlRpc\Response(new Value($numCurly, "int"));
 }
 
-$v1_easyStruct_sig = array(array($xmlrpcInt, $xmlrpcStruct));
+$v1_easyStruct_sig = array(array(Value::$xmlrpcInt, Value::$xmlrpcStruct));
 $v1_easyStruct_doc = 'This handler takes a single parameter, a struct, containing at least three elements named moe, larry and curly, all &lt;i4&gt;s. Your handler must add the three numbers and return the result.';
 function v1_easyStruct($m)
 {
@@ -454,10 +442,10 @@ function v1_easyStruct($m)
     $curly = $sno->structmem("curly");
     $num = $moe->scalarval() + $larry->scalarval() + $curly->scalarval();
 
-    return new PhpXmlRpc\Response(new PhpXmlRpc\Value($num, "int"));
+    return new PhpXmlRpc\Response(new Value($num, "int"));
 }
 
-$v1_echoStruct_sig = array(array($xmlrpcStruct, $xmlrpcStruct));
+$v1_echoStruct_sig = array(array(Value::$xmlrpcStruct, Value::$xmlrpcStruct));
 $v1_echoStruct_doc = 'This handler takes a single parameter, a struct. Your handler must return the struct.';
 function v1_echoStruct($m)
 {
@@ -467,14 +455,14 @@ function v1_echoStruct($m)
 }
 
 $v1_manyTypes_sig = array(array(
-    $xmlrpcArray, $xmlrpcInt, $xmlrpcBoolean,
-    $xmlrpcString, $xmlrpcDouble, $xmlrpcDateTime,
-    $xmlrpcBase64,
+    Value::$xmlrpcArray, Value::$xmlrpcInt, Value::$xmlrpcBoolean,
+    Value::$xmlrpcString, Value::$xmlrpcDouble, Value::$xmlrpcDateTime,
+    Value::$xmlrpcBase64,
 ));
 $v1_manyTypes_doc = 'This handler takes six parameters, and returns an array containing all the parameters.';
 function v1_manyTypes($m)
 {
-    return new PhpXmlRpc\Response(new PhpXmlRpc\Value(array(
+    return new PhpXmlRpc\Response(new Value(array(
         $m->getParam(0),
         $m->getParam(1),
         $m->getParam(2),
@@ -485,7 +473,7 @@ function v1_manyTypes($m)
     ));
 }
 
-$v1_moderateSizeArrayCheck_sig = array(array($xmlrpcString, $xmlrpcArray));
+$v1_moderateSizeArrayCheck_sig = array(array(Value::$xmlrpcString, Value::$xmlrpcArray));
 $v1_moderateSizeArrayCheck_doc = 'This handler takes a single parameter, which is an array containing between 100 and 200 elements. Each of the items is a string, your handler must return a string containing the concatenated text of the first and last elements.';
 function v1_moderateSizeArrayCheck($m)
 {
@@ -494,26 +482,26 @@ function v1_moderateSizeArrayCheck($m)
     $first = $ar->arraymem(0);
     $last = $ar->arraymem($sz - 1);
 
-    return new PhpXmlRpc\Response(new PhpXmlRpc\Value($first->scalarval() .
+    return new PhpXmlRpc\Response(new Value($first->scalarval() .
         $last->scalarval(), "string"));
 }
 
-$v1_simpleStructReturn_sig = array(array($xmlrpcStruct, $xmlrpcInt));
+$v1_simpleStructReturn_sig = array(array(Value::$xmlrpcStruct, Value::$xmlrpcInt));
 $v1_simpleStructReturn_doc = 'This handler takes one parameter, and returns a struct containing three elements, times10, times100 and times1000, the result of multiplying the number by 10, 100 and 1000.';
 function v1_simpleStructReturn($m)
 {
     $sno = $m->getParam(0);
     $v = $sno->scalarval();
 
-    return new PhpXmlRpc\Response(new PhpXmlRpc\Value(array(
-        "times10" => new PhpXmlRpc\Value($v * 10, "int"),
-        "times100" => new PhpXmlRpc\Value($v * 100, "int"),
-        "times1000" => new PhpXmlRpc\Value($v * 1000, "int"),),
+    return new PhpXmlRpc\Response(new Value(array(
+        "times10" => new Value($v * 10, "int"),
+        "times100" => new Value($v * 100, "int"),
+        "times1000" => new Value($v * 1000, "int"),),
         "struct"
     ));
 }
 
-$v1_nestedStruct_sig = array(array($xmlrpcInt, $xmlrpcStruct));
+$v1_nestedStruct_sig = array(array(Value::$xmlrpcInt, Value::$xmlrpcStruct));
 $v1_nestedStruct_doc = 'This handler takes a single parameter, a struct, that models a daily calendar. At the top level, there is one struct for each year. Each year is broken down into months, and months into days. Most of the days are empty in the struct you receive, but the entry for April 1, 2000 contains a least three elements named moe, larry and curly, all &lt;i4&gt;s. Your handler must add the three numbers and return the result.';
 function v1_nestedStruct($m)
 {
@@ -526,10 +514,10 @@ function v1_nestedStruct($m)
     $larry = $fools->structmem("larry");
     $moe = $fools->structmem("moe");
 
-    return new PhpXmlRpc\Response(new PhpXmlRpc\Value($curly->scalarval() + $larry->scalarval() + $moe->scalarval(), "int"));
+    return new PhpXmlRpc\Response(new Value($curly->scalarval() + $larry->scalarval() + $moe->scalarval(), "int"));
 }
 
-$v1_countTheEntities_sig = array(array($xmlrpcStruct, $xmlrpcString));
+$v1_countTheEntities_sig = array(array(Value::$xmlrpcStruct, Value::$xmlrpcString));
 $v1_countTheEntities_doc = 'This handler takes a single parameter, a string, that contains any number of predefined entities, namely &lt;, &gt;, &amp; \' and ".<BR>Your handler must return a struct that contains five fields, all numbers: ctLeftAngleBrackets, ctRightAngleBrackets, ctAmpersands, ctApostrophes, ctQuotes.';
 function v1_countTheEntities($m)
 {
@@ -563,12 +551,12 @@ function v1_countTheEntities($m)
         }
     }
 
-    return new PhpXmlRpc\Response(new PhpXmlRpc\Value(array(
-        "ctLeftAngleBrackets" => new PhpXmlRpc\Value($lt, "int"),
-        "ctRightAngleBrackets" => new PhpXmlRpc\Value($gt, "int"),
-        "ctAmpersands" => new PhpXmlRpc\Value($amp, "int"),
-        "ctApostrophes" => new PhpXmlRpc\Value($ap, "int"),
-        "ctQuotes" => new PhpXmlRpc\Value($qu, "int"),),
+    return new PhpXmlRpc\Response(new Value(array(
+        "ctLeftAngleBrackets" => new Value($lt, "int"),
+        "ctRightAngleBrackets" => new Value($gt, "int"),
+        "ctAmpersands" => new Value($amp, "int"),
+        "ctApostrophes" => new Value($ap, "int"),
+        "ctQuotes" => new Value($qu, "int"),),
         "struct"
     ));
 }
@@ -576,37 +564,37 @@ function v1_countTheEntities($m)
 // trivial interop tests
 // http://www.xmlrpc.com/stories/storyReader$1636
 
-$i_echoString_sig = array(array($xmlrpcString, $xmlrpcString));
+$i_echoString_sig = array(array(Value::$xmlrpcString, Value::$xmlrpcString));
 $i_echoString_doc = "Echoes string.";
 
-$i_echoStringArray_sig = array(array($xmlrpcArray, $xmlrpcArray));
+$i_echoStringArray_sig = array(array(Value::$xmlrpcArray, Value::$xmlrpcArray));
 $i_echoStringArray_doc = "Echoes string array.";
 
-$i_echoInteger_sig = array(array($xmlrpcInt, $xmlrpcInt));
+$i_echoInteger_sig = array(array(Value::$xmlrpcInt, Value::$xmlrpcInt));
 $i_echoInteger_doc = "Echoes integer.";
 
-$i_echoIntegerArray_sig = array(array($xmlrpcArray, $xmlrpcArray));
+$i_echoIntegerArray_sig = array(array(Value::$xmlrpcArray, Value::$xmlrpcArray));
 $i_echoIntegerArray_doc = "Echoes integer array.";
 
-$i_echoFloat_sig = array(array($xmlrpcDouble, $xmlrpcDouble));
+$i_echoFloat_sig = array(array(Value::$xmlrpcDouble, Value::$xmlrpcDouble));
 $i_echoFloat_doc = "Echoes float.";
 
-$i_echoFloatArray_sig = array(array($xmlrpcArray, $xmlrpcArray));
+$i_echoFloatArray_sig = array(array(Value::$xmlrpcArray, Value::$xmlrpcArray));
 $i_echoFloatArray_doc = "Echoes float array.";
 
-$i_echoStruct_sig = array(array($xmlrpcStruct, $xmlrpcStruct));
+$i_echoStruct_sig = array(array(Value::$xmlrpcStruct, Value::$xmlrpcStruct));
 $i_echoStruct_doc = "Echoes struct.";
 
-$i_echoStructArray_sig = array(array($xmlrpcArray, $xmlrpcArray));
+$i_echoStructArray_sig = array(array(Value::$xmlrpcArray, Value::$xmlrpcArray));
 $i_echoStructArray_doc = "Echoes struct array.";
 
 $i_echoValue_doc = "Echoes any value back.";
-$i_echoValue_sig = array(array($xmlrpcValue, $xmlrpcValue));
+$i_echoValue_sig = array(array(Value::$xmlrpcValue, Value::$xmlrpcValue));
 
-$i_echoBase64_sig = array(array($xmlrpcBase64, $xmlrpcBase64));
+$i_echoBase64_sig = array(array(Value::$xmlrpcBase64, Value::$xmlrpcBase64));
 $i_echoBase64_doc = "Echoes base64.";
 
-$i_echoDate_sig = array(array($xmlrpcDateTime, $xmlrpcDateTime));
+$i_echoDate_sig = array(array(Value::$xmlrpcDateTime, Value::$xmlrpcDateTime));
 $i_echoDate_doc = "Echoes dateTime.";
 
 function i_echoParam($m)
@@ -671,69 +659,72 @@ function i_echoDate($m)
     return i_echoParam($m);
 }
 
-$i_whichToolkit_sig = array(array($xmlrpcStruct));
+$i_whichToolkit_sig = array(array(Value::$xmlrpcStruct));
 $i_whichToolkit_doc = "Returns a struct containing the following strings: toolkitDocsUrl, toolkitName, toolkitVersion, toolkitOperatingSystem.";
 
 function i_whichToolkit($m)
 {
-    global $xmlrpcName, $xmlrpcVersion, $SERVER_SOFTWARE;
+    global $SERVER_SOFTWARE;
     $ret = array(
         "toolkitDocsUrl" => "http://phpxmlrpc.sourceforge.net/",
-        "toolkitName" => $xmlrpcName,
-        "toolkitVersion" => $xmlrpcVersion,
+        "toolkitName" => PhpXmlRpc\PhpXmlRpc::$xmlrpcName,
+        "toolkitVersion" => PhpXmlRpc\PhpXmlRpc::$xmlrpcVersion,
         "toolkitOperatingSystem" => isset($SERVER_SOFTWARE) ? $SERVER_SOFTWARE : $_SERVER['SERVER_SOFTWARE'],
     );
 
-    return new PhpXmlRpc\Response(php_xmlrpc_encode($ret));
+    $encoder = new PhpXmlRpc\Encoder();
+    return new PhpXmlRpc\Response($encoder->encode($ret));
 }
 
-$o = new xmlrpc_server_methods_container();
-$a = array(
+$object = new xmlrpcServerMethodsContainer();
+$signatures = array(
     "examples.getStateName" => array(
-        "function" => "findstate",
+        "function" => "findState",
         "signature" => $findstate_sig,
         "docstring" => $findstate_doc,
     ),
     "examples.sortByAge" => array(
-        "function" => "agesorter",
+        "function" => "ageSorter",
         "signature" => $agesorter_sig,
         "docstring" => $agesorter_doc,
     ),
     "examples.addtwo" => array(
-        "function" => "addtwo",
+        "function" => "addTwo",
         "signature" => $addtwo_sig,
         "docstring" => $addtwo_doc,
     ),
     "examples.addtwodouble" => array(
-        "function" => "addtwodouble",
+        "function" => "addTwoDouble",
         "signature" => $addtwodouble_sig,
         "docstring" => $addtwodouble_doc,
     ),
     "examples.stringecho" => array(
-        "function" => "stringecho",
+        "function" => "stringEcho",
         "signature" => $stringecho_sig,
         "docstring" => $stringecho_doc,
     ),
     "examples.echo" => array(
-        "function" => "echoback",
+        "function" => "echoBack",
         "signature" => $echoback_sig,
         "docstring" => $echoback_doc,
     ),
     "examples.decode64" => array(
-        "function" => "echosixtyfour",
+        "function" => "echoSixtyFour",
         "signature" => $echosixtyfour_sig,
         "docstring" => $echosixtyfour_doc,
     ),
     "examples.invertBooleans" => array(
-        "function" => "bitflipper",
+        "function" => "bitFlipper",
         "signature" => $bitflipper_sig,
         "docstring" => $bitflipper_doc,
     ),
+    // signature omitted on purpose
     "examples.generatePHPWarning" => array(
-        "function" => array($o, "phpwarninggenerator"),
+        "function" => array($object, "phpWarningGenerator"),
     ),
+    // signature omitted on purpose
     "examples.raiseException" => array(
-        "function" => array($o, "exceptiongenerator"),
+        "function" => array($object, "exceptionGenerator"),
     ),
     "examples.getallheaders" => array(
         "function" => 'getallheaders_xmlrpc',
@@ -741,19 +732,19 @@ $a = array(
         "docstring" => $getallheaders_doc,
     ),
     "examples.setcookies" => array(
-        "function" => 'setcookies',
+        "function" => 'setCookies',
         "signature" => $setcookies_sig,
         "docstring" => $setcookies_doc,
     ),
     "examples.getcookies" => array(
-        "function" => 'getcookies',
+        "function" => 'getCookies',
         "signature" => $getcookies_sig,
         "docstring" => $getcookies_doc,
     ),
     "mail.send" => array(
-        "function" => "mail_send",
-        "signature" => $mail_send_sig,
-        "docstring" => $mail_send_doc,
+        "function" => "mailSend",
+        "signature" => $mailsend_sig,
+        "docstring" => $mailsend_doc,
     ),
     "validator1.arrayOfStructsTest" => array(
         "function" => "v1_arrayOfStructs",
@@ -858,22 +849,22 @@ $a = array(
 );
 
 if ($findstate2_sig) {
-    $a['examples.php.getStateName'] = $findstate2_sig;
+    $signatures['examples.php.getStateName'] = $findstate2_sig;
 }
 
 if ($findstate3_sig) {
-    $a['examples.php2.getStateName'] = $findstate3_sig;
+    $signatures['examples.php2.getStateName'] = $findstate3_sig;
 }
 
 if ($findstate4_sig) {
-    $a['examples.php3.getStateName'] = $findstate4_sig;
+    $signatures['examples.php3.getStateName'] = $findstate4_sig;
 }
 
 if ($findstate5_sig) {
-    $a['examples.php4.getStateName'] = $findstate5_sig;
+    $signatures['examples.php4.getStateName'] = $findstate5_sig;
 }
 
-$s = new PhpXmlRpc\Server($a, false);
+$s = new PhpXmlRpc\Server($signatures, false);
 $s->setdebug(3);
 $s->compress_response = true;