Implement interface ArrayAccess in the Value class
[plcapi.git] / demo / server / server.php
index aa604b8..d060d97 100644 (file)
@@ -37,8 +37,10 @@ class xmlrpcServerMethodsContainer
 {
     /**
      * Method used to test logging of php warnings generated by user functions.
+     * @param PhpXmlRpc\Request $req
+     * @return PhpXmlRpc\Response
      */
-    public function phpWarningGenerator($m)
+    public function phpWarningGenerator($req)
     {
         $a = $undefinedVariable; // this triggers a warning in E_ALL mode, since $undefinedVariable is undefined
         return new PhpXmlRpc\Response(new Value(1, 'boolean'));
@@ -46,20 +48,44 @@ class xmlrpcServerMethodsContainer
 
     /**
      * Method used to test catching of exceptions in the server.
+     * @param PhpXmlRpc\Request $req
+     * @throws Exception
      */
-    public function exceptionGenerator($m)
+    public function exceptionGenerator($req)
     {
         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
-    * @param integer $s
-    * @return string
-    */
-    public static function findState($s)
+     * @param string $msg
+     */
+    public function debugMessageGenerator($msg)
+    {
+        PhpXmlRpc\Server::xmlrpc_debugmsg($msg);
+    }
+
+    /**
+     * A PHP version of the state-number server. Send me an integer and i'll sell you a state.
+     * Used to test wrapping of PHP methods into xmlrpc methods.
+     *
+     * @param integer $num
+     * @return string
+     * @throws Exception
+     */
+    public static function findState($num)
     {
-        return inner_findstate($s);
+        return inner_findstate($num);
+    }
+
+    /**
+     * Returns an instance of stdClass.
+     * Used to test wrapping of PHP objects with class preservation
+     */
+    public function returnObject()
+    {
+        $obj = new stdClass();
+        $obj->hello = 'world';
+        return $obj;
     }
 }
 
@@ -83,13 +109,13 @@ $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($req)
 {
     global $stateNames;
 
     $err = "";
     // get the first param
-    $sno = $m->getParam(0);
+    $sno = $req->getParam(0);
 
     // param must be there and of the correct type: server object does the validation for us
 
@@ -114,11 +140,13 @@ function findState($m)
 
 /**
  * Inner code of the state-number server.
- * Used to test auto-registration of PHP functions as xmlrpc methods.
+ * Used to test wrapping of PHP functions into xmlrpc methods.
  *
  * @param integer $stateNo the state number
  *
  * @return string the name of the state (or error description)
+ *
+ * @throws Exception if state is not found
  */
 function inner_findstate($stateNo)
 {
@@ -128,80 +156,122 @@ function inner_findstate($stateNo)
         return $stateNames[$stateNo - 1];
     } else {
         // not, there so complain
-        return "I don't have a state for the index '" . $stateNo . "'";
+        throw new Exception("I don't have a state for the index '" . $stateNo . "'", PhpXmlRpc\PhpXmlRpc::$xmlrpcerruser);
     }
 }
 
 $wrapper = new PhpXmlRpc\Wrapper();
 
-$findstate2_sig = $wrapper->wrap_php_function('inner_findstate');
+$findstate2_sig = $wrapper->wrapPhpFunction('inner_findstate');
+
+$findstate3_sig = $wrapper->wrapPhpFunction(array('xmlrpcServerMethodsContainer', 'findState'));
+
+$obj = new xmlrpcServerMethodsContainer();
+$findstate4_sig = $wrapper->wrapPhpFunction(array($obj, 'findstate'));
 
-$findstate3_sig = $wrapper->wrap_php_function(array('xmlrpcServerMethodsContainer', 'findState'));
+$findstate5_sig = $wrapper->wrapPhpFunction('xmlrpcServerMethodsContainer::findState', '', array('return_source' => true));
+eval($findstate5_sig['source']);
 
-$findstate5_sig = $wrapper->wrap_php_function('xmlrpcServerMethodsContainer::findState');
+$findstate6_sig = $wrapper->wrapPhpFunction('inner_findstate', '', array('return_source' => true));
+eval($findstate6_sig['source']);
+
+$findstate7_sig = $wrapper->wrapPhpFunction(array('xmlrpcServerMethodsContainer', 'findState'), '', array('return_source' => true));
+eval($findstate7_sig['source']);
 
 $obj = new xmlrpcServerMethodsContainer();
-$findstate4_sig = $wrapper->wrap_php_function(array($obj, 'findstate'));
+$findstate8_sig = $wrapper->wrapPhpFunction(array($obj, 'findstate'), '', array('return_source' => true));
+eval($findstate8_sig['source']);
+
+$findstate9_sig = $wrapper->wrapPhpFunction('xmlrpcServerMethodsContainer::findState', '', array('return_source' => true));
+eval($findstate9_sig['source']);
+
+$findstate10_sig = array(
+    "function" => function ($req) { return findState($req); },
+    "signature" => $findstate_sig,
+    "docstring" => $findstate_doc,
+);
+
+$findstate11_sig = $wrapper->wrapPhpFunction(function ($stateNo) { return inner_findstate($stateNo); });
+
+$c = new xmlrpcServerMethodsContainer;
+$moreSignatures = $wrapper->wrapPhpClass($c, array('prefix' => 'tests.', 'method_type' => 'all'));
+
+$returnObj_sig =  $wrapper->wrapPhpFunction(array($c, 'returnObject'), '', array('encode_php_objs' => true));
+
+// used to test signatures with NULL params
+$findstate12_sig = array(
+    array(Value::$xmlrpcString, Value::$xmlrpcInt, Value::$xmlrpcNull),
+    array(Value::$xmlrpcString, Value::$xmlrpcNull, Value::$xmlrpcInt),
+);
+
+function findStateWithNulls($req)
+{
+    $a = $req->getParam(0);
+    $b = $req->getParam(1);
+
+    if ($a->scalartyp() == Value::$xmlrpcNull)
+        return new PhpXmlRpc\Response(new Value(inner_findstate($b->scalarval())));
+    else
+        return new PhpXmlRpc\Response(new Value(inner_findstate($a->scalarval())));
+}
 
 $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($req)
 {
-    $s = $m->getParam(0);
-    $t = $m->getParam(1);
+    $s = $req->getParam(0);
+    $t = $req->getParam(1);
 
     return new PhpXmlRpc\Response(new Value($s->scalarval() + $t->scalarval(), "int"));
 }
 
 $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($req)
 {
-    $s = $m->getParam(0);
-    $t = $m->getParam(1);
+    $s = $req->getParam(0);
+    $t = $req->getParam(1);
 
     return new PhpXmlRpc\Response(new Value($s->scalarval() + $t->scalarval(), "double"));
 }
 
 $stringecho_sig = array(array(Value::$xmlrpcString, Value::$xmlrpcString));
 $stringecho_doc = 'Accepts a string parameter, returns the string.';
-function stringEcho($m)
+function stringEcho($req)
 {
     // just sends back a string
-    return new PhpXmlRpc\Response(new Value($m->getParam(0)->scalarval()));
+    return new PhpXmlRpc\Response(new Value($req->getParam(0)->scalarval()));
 }
 
 $echoback_sig = array(array(Value::$xmlrpcString, Value::$xmlrpcString));
 $echoback_doc = 'Accepts a string parameter, returns the entire incoming payload';
-function echoBack($m)
+function echoBack($req)
 {
     // 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();
+    $s = "I got the following message:\n" . $req->serialize();
 
     return new PhpXmlRpc\Response(new Value($s));
 }
 
 $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($req)
 {
     // Accepts an encoded value, but sends it back as a normal string.
     // This is to test that base64 encoding is working as expected
-    $incoming = $m->getParam(0);
+    $incoming = $req->getParam(0);
 
     return new PhpXmlRpc\Response(new Value($incoming->scalarval(), "string"));
 }
 
 $bitflipper_sig = array(array(Value::$xmlrpcArray, Value::$xmlrpcArray));
 $bitflipper_doc = 'Accepts an array of booleans, and returns them inverted';
-function bitFlipper($m)
+function bitFlipper($req)
 {
-    $v = $m->getParam(0);
-    $sz = $v->arraysize();
+    $v = $req->getParam(0);
     $rv = new Value(array(), Value::$xmlrpcArray);
 
-    for ($j = 0; $j < $sz; $j++) {
-        $b = $v->arraymem($j);
+    foreach ($v as $b) {
         if ($b->scalarval()) {
             $rv->addScalar(false, "boolean");
         } else {
@@ -248,23 +318,22 @@ $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($req)
 {
     global $agesorter_arr, $s;
 
     PhpXmlRpc\Server::xmlrpc_debugmsg("Entering 'agesorter'");
     // get the parameter
-    $sno = $m->getParam(0);
+    $sno = $req->getParam(0);
     // error string for [if|when] things go wrong
     $err = "";
     // create the output value
     $v = new Value();
     $agar = array();
 
-    $max = $sno->arraysize();
+    $max = $sno->count();
     PhpXmlRpc\Server::xmlrpc_debugmsg("Found $max array elements");
-    for ($i = 0; $i < $max; $i++) {
-        $rec = $sno->arraymem($i);
+    foreach ($sno as $rec) {
         if ($rec->kindOf() != "struct") {
             $err = "Found non-struct in array at element $i";
             break;
@@ -297,8 +366,7 @@ function ageSorter($m)
     }
 }
 
-// signature and instructions, place these in the dispatch
-// map
+// signature and instructions, place these in the dispatch map
 $mailsend_sig = array(array(
     Value::$xmlrpcBoolean, Value::$xmlrpcString, Value::$xmlrpcString,
     Value::$xmlrpcString, Value::$xmlrpcString, Value::$xmlrpcString,
@@ -315,17 +383,17 @@ 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 mailSend($m)
+function mailSend($req)
 {
     $err = "";
 
-    $mTo = $m->getParam(0);
-    $mSub = $m->getParam(1);
-    $mBody = $m->getParam(2);
-    $mFrom = $m->getParam(3);
-    $mCc = $m->getParam(4);
-    $mBcc = $m->getParam(5);
-    $mMime = $m->getParam(6);
+    $mTo = $req->getParam(0);
+    $mSub = $req->getParam(1);
+    $mBody = $req->getParam(2);
+    $mFrom = $req->getParam(3);
+    $mCc = $req->getParam(4);
+    $mBcc = $req->getParam(5);
+    $mMime = $req->getParam(6);
 
     if ($mTo->scalarval() == "") {
         $err = "Error, no 'To' field specified";
@@ -335,25 +403,25 @@ function mailSend($m)
         $err = "Error, no 'From' field specified";
     }
 
-    $msghdr = "From: " . $mFrom->scalarval() . "\n";
-    $msghdr .= "To: " . $mTo->scalarval() . "\n";
+    $msgHdr = "From: " . $mFrom->scalarval() . "\n";
+    $msgHdr .= "To: " . $mTo->scalarval() . "\n";
 
     if ($mCc->scalarval() != "") {
-        $msghdr .= "Cc: " . $mCc->scalarval() . "\n";
+        $msgHdr .= "Cc: " . $mCc->scalarval() . "\n";
     }
     if ($mBcc->scalarval() != "") {
-        $msghdr .= "Bcc: " . $mBcc->scalarval() . "\n";
+        $msgHdr .= "Bcc: " . $mBcc->scalarval() . "\n";
     }
     if ($mMime->scalarval() != "") {
-        $msghdr .= "Content-type: " . $mMime->scalarval() . "\n";
+        $msgHdr .= "Content-type: " . $mMime->scalarval() . "\n";
     }
-    $msghdr .= "X-Mailer: XML-RPC for PHP mailer 1.0";
+    $msgHdr .= "X-Mailer: XML-RPC for PHP mailer 1.0";
 
     if ($err == "") {
         if (!mail("",
             $mSub->scalarval(),
             $mBody->scalarval(),
-            $msghdr)
+            $msgHdr)
         ) {
             $err = "Error, could not send the mail.";
         }
@@ -368,7 +436,7 @@ function mailSend($m)
 
 $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)
+function getAllHeaders_xmlrpc($req)
 {
     $encoder = new PhpXmlRpc\Encoder();
 
@@ -390,11 +458,11 @@ function getallheaders_xmlrpc($m)
 
 $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($req)
 {
     $encoder = new PhpXmlRpc\Encoder();
-    $m = $m->getParam(0);
-    while (list($name, $value) = $m->structeach()) {
+    $cookies = $req->getParam(0);
+    foreach ($cookies as $name => $value) {
         $cookieDesc = $encoder->decode($value);
         setcookie($name, @$cookieDesc['value'], @$cookieDesc['expires'], @$cookieDesc['path'], @$cookieDesc['domain'], @$cookieDesc['secure']);
     }
@@ -404,7 +472,7 @@ function setCookies($m)
 
 $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($req)
 {
     $encoder = new PhpXmlRpc\Encoder();
     return new PhpXmlRpc\Response($encoder->encode($_COOKIE));
@@ -412,14 +480,12 @@ function getCookies($m)
 
 $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)
+function v1_arrayOfStructs($req)
 {
-    $sno = $m->getParam(0);
+    $sno = $req->getParam(0);
     $numCurly = 0;
-    for ($i = 0; $i < $sno->arraysize(); $i++) {
-        $str = $sno->arraymem($i);
-        $str->structreset();
-        while (list($key, $val) = $str->structeach()) {
+    foreach ($sno as $str) {
+        foreach ($str as $key => $val) {
             if ($key == "curly") {
                 $numCurly += $val->scalarval();
             }
@@ -431,9 +497,9 @@ function v1_arrayOfStructs($m)
 
 $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)
+function v1_easyStruct($req)
 {
-    $sno = $m->getParam(0);
+    $sno = $req->getParam(0);
     $moe = $sno->structmem("moe");
     $larry = $sno->structmem("larry");
     $curly = $sno->structmem("curly");
@@ -444,9 +510,9 @@ function v1_easyStruct($m)
 
 $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)
+function v1_echoStruct($req)
 {
-    $sno = $m->getParam(0);
+    $sno = $req->getParam(0);
 
     return new PhpXmlRpc\Response($sno);
 }
@@ -457,27 +523,29 @@ $v1_manyTypes_sig = array(array(
     Value::$xmlrpcBase64,
 ));
 $v1_manyTypes_doc = 'This handler takes six parameters, and returns an array containing all the parameters.';
-function v1_manyTypes($m)
+function v1_manyTypes($req)
 {
     return new PhpXmlRpc\Response(new Value(array(
-        $m->getParam(0),
-        $m->getParam(1),
-        $m->getParam(2),
-        $m->getParam(3),
-        $m->getParam(4),
-        $m->getParam(5),),
+        $req->getParam(0),
+        $req->getParam(1),
+        $req->getParam(2),
+        $req->getParam(3),
+        $req->getParam(4),
+        $req->getParam(5),),
         "array"
     ));
 }
 
 $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)
+function v1_moderateSizeArrayCheck($req)
 {
-    $ar = $m->getParam(0);
-    $sz = $ar->arraysize();
-    $first = $ar->arraymem(0);
-    $last = $ar->arraymem($sz - 1);
+    $ar = $req->getParam(0);
+    $sz = $ar->count();
+    //$first = $ar->arraymem(0);
+    $first = $ar[0];
+    //$last = $ar->arraymem($sz - 1);
+    $last = $ar[$sz - 1];
 
     return new PhpXmlRpc\Response(new Value($first->scalarval() .
         $last->scalarval(), "string"));
@@ -485,9 +553,9 @@ function v1_moderateSizeArrayCheck($m)
 
 $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)
+function v1_simpleStructReturn($req)
 {
-    $sno = $m->getParam(0);
+    $sno = $req->getParam(0);
     $v = $sno->scalarval();
 
     return new PhpXmlRpc\Response(new Value(array(
@@ -500,9 +568,9 @@ function v1_simpleStructReturn($m)
 
 $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)
+function v1_nestedStruct($req)
 {
-    $sno = $m->getParam(0);
+    $sno = $req->getParam(0);
 
     $twoK = $sno->structmem("2000");
     $april = $twoK->structmem("04");
@@ -516,9 +584,9 @@ function v1_nestedStruct($m)
 
 $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)
+function v1_countTheEntities($req)
 {
-    $sno = $m->getParam(0);
+    $sno = $req->getParam(0);
     $str = $sno->scalarval();
     $gt = 0;
     $lt = 0;
@@ -594,72 +662,72 @@ $i_echoBase64_doc = "Echoes base64.";
 $i_echoDate_sig = array(array(Value::$xmlrpcDateTime, Value::$xmlrpcDateTime));
 $i_echoDate_doc = "Echoes dateTime.";
 
-function i_echoParam($m)
+function i_echoParam($req)
 {
-    $s = $m->getParam(0);
+    $s = $req->getParam(0);
 
     return new PhpXmlRpc\Response($s);
 }
 
-function i_echoString($m)
+function i_echoString($req)
 {
-    return i_echoParam($m);
+    return i_echoParam($req);
 }
 
-function i_echoInteger($m)
+function i_echoInteger($req)
 {
-    return i_echoParam($m);
+    return i_echoParam($req);
 }
 
-function i_echoFloat($m)
+function i_echoFloat($req)
 {
-    return i_echoParam($m);
+    return i_echoParam($req);
 }
 
-function i_echoStruct($m)
+function i_echoStruct($req)
 {
-    return i_echoParam($m);
+    return i_echoParam($req);
 }
 
-function i_echoStringArray($m)
+function i_echoStringArray($req)
 {
-    return i_echoParam($m);
+    return i_echoParam($req);
 }
 
-function i_echoIntegerArray($m)
+function i_echoIntegerArray($req)
 {
-    return i_echoParam($m);
+    return i_echoParam($req);
 }
 
-function i_echoFloatArray($m)
+function i_echoFloatArray($req)
 {
-    return i_echoParam($m);
+    return i_echoParam($req);
 }
 
-function i_echoStructArray($m)
+function i_echoStructArray($req)
 {
-    return i_echoParam($m);
+    return i_echoParam($req);
 }
 
-function i_echoValue($m)
+function i_echoValue($req)
 {
-    return i_echoParam($m);
+    return i_echoParam($req);
 }
 
-function i_echoBase64($m)
+function i_echoBase64($req)
 {
-    return i_echoParam($m);
+    return i_echoParam($req);
 }
 
-function i_echoDate($m)
+function i_echoDate($req)
 {
-    return i_echoParam($m);
+    return i_echoParam($req);
 }
 
 $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)
+function i_whichToolkit($req)
 {
     global $SERVER_SOFTWARE;
     $ret = array(
@@ -736,7 +804,7 @@ $signatures = array(
         "docstring" => $stringecho_doc,
     ),*/
     "examples.getallheaders" => array(
-        "function" => 'getallheaders_xmlrpc',
+        "function" => 'getAllHeaders_xmlrpc',
         "signature" => $getallheaders_sig,
         "docstring" => $getallheaders_doc,
     ),
@@ -855,23 +923,31 @@ $signatures = array(
         "signature" => $i_whichToolkit_sig,
         "docstring" => $i_whichToolkit_doc,
     ),
-);
 
-if ($findstate2_sig) {
-    $signatures['examples.php.getStateName'] = $findstate2_sig;
-}
+    'tests.getStateName.2' => $findstate2_sig,
+    'tests.getStateName.3' => $findstate3_sig,
+    'tests.getStateName.4' => $findstate4_sig,
+    'tests.getStateName.5' => $findstate5_sig,
+    'tests.getStateName.6' => $findstate6_sig,
+    'tests.getStateName.7' => $findstate7_sig,
+    'tests.getStateName.8' => $findstate8_sig,
+    'tests.getStateName.9' => $findstate9_sig,
+    'tests.getStateName.10' => $findstate10_sig,
+    'tests.getStateName.11' => $findstate11_sig,
+
+    'tests.getStateName.12' => array(
+        "function" => "findStateWithNulls",
+        "signature" => $findstate12_sig,
+        "docstring" => $findstate_doc,
+    ),
 
-if ($findstate3_sig) {
-    $signatures['examples.php2.getStateName'] = $findstate3_sig;
-}
+    'tests.returnPhpObject' => $returnObj_sig,
+);
 
-if ($findstate4_sig) {
-    $signatures['examples.php3.getStateName'] = $findstate4_sig;
-}
+$signatures = array_merge($signatures, $moreSignatures);
 
-if ($findstate5_sig) {
-    $signatures['examples.php4.getStateName'] = $findstate5_sig;
-}
+// enable support for the NULL extension
+PhpXmlRpc\PhpXmlRpc::$xmlrpc_null_extension = true;
 
 $s = new PhpXmlRpc\Server($signatures, false);
 $s->setdebug(3);
@@ -882,6 +958,9 @@ $s->compress_response = true;
 if (isset($_GET['RESPONSE_ENCODING'])) {
     $s->response_charset_encoding = $_GET['RESPONSE_ENCODING'];
 }
+if (isset($_GET['DETECT_ENCODINGS'])) {
+    PhpXmlRpc\PhpXmlRpc::$xmlrpc_detectencodings = $_GET['DETECT_ENCODINGS'];
+}
 if (isset($_GET['EXCEPTION_HANDLING'])) {
     $s->exception_handling = $_GET['EXCEPTION_HANDLING'];
 }