From a48c09b3cc49bc7f603cd5b06de74ee2d2878ca4 Mon Sep 17 00:00:00 2001 From: gggeek <giunta.gaetano@gmail.com> Date: Sun, 12 Jul 2015 20:47:00 +0100 Subject: [PATCH] Clean up old-API code --- debugger/action.php | 7 --- demo/client/agesort.php | 2 - demo/client/introspect.php | 2 - demo/server/server.php | 113 ++++++++++++++++++++----------------- src/Client.php | 5 -- src/Encoder.php | 5 -- src/Request.php | 2 - src/Server.php | 8 --- 8 files changed, 60 insertions(+), 84 deletions(-) diff --git a/debugger/action.php b/debugger/action.php index 3b014445..0d0a649e 100644 --- a/debugger/action.php +++ b/debugger/action.php @@ -287,9 +287,7 @@ if ($action) { $max = $v->count(); echo "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n"; echo "<thead>\n<tr><th>Method ($max)</th><th>Description</th></tr>\n</thead>\n<tbody>\n"; - //for ($i = 0; $i < $max; $i++) { foreach($v as $i => $rec) { - //$rec = $v->arraymem($i); if ($i % 2) { $class = ' class="oddrow"'; } else { @@ -355,7 +353,6 @@ if ($action) { if ($r2->kindOf() != "array") { echo "<tr><td class=\"oddrow\">Signature</td><td class=\"oddrow\">Unknown</td><td class=\"oddrow\"> </td></tr>\n"; } else { - //for ($i = 0; $i < $r2->arraysize(); $i++) { foreach($r2 as $i => $x) { $payload = ""; $alt_payload = ""; @@ -365,16 +362,12 @@ if ($action) { $class = ' class="evenrow"'; } echo "<tr><td$class>Signature " . ($i + 1) . "</td><td$class>"; - //$x = $r2->arraymem($i); if ($x->kindOf() == "array") { - //$ret = $x->arraymem(0); $ret = $x[0]; echo "<code>OUT: " . htmlspecialchars($ret->scalarval(), ENT_COMPAT, \PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding) . "<br />IN: ("; if ($x->count() > 1) { foreach($x as $k => $y) { if ($k == 0) continue; - //for ($k = 1; $k < $x->arraysize(); $k++) { - //$y = $x->arraymem($k); echo htmlspecialchars($y->scalarval(), ENT_COMPAT, \PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding); if ($wstype != 1) { $type = $y->scalarval(); diff --git a/demo/client/agesort.php b/demo/client/agesort.php index 0b6aa9a9..90622d21 100644 --- a/demo/client/agesort.php +++ b/demo/client/agesort.php @@ -50,9 +50,7 @@ if (!$resp->faultCode()) { print "The server gave me these results:<pre>"; $value = $resp->value(); foreach ($value as $struct) { - //$name = $struct->structmem("name"); $name = $struct["name"]; - //$age = $struct->structmem("age"); $age = $struct["age"]; print htmlspecialchars($name->scalarval()) . ", " . htmlspecialchars($age->scalarval()) . "\n"; } diff --git a/demo/client/introspect.php b/demo/client/introspect.php index 5c359504..7870a94c 100644 --- a/demo/client/introspect.php +++ b/demo/client/introspect.php @@ -60,13 +60,11 @@ if ($resp->faultCode()) { $val = $rs[1]->value(); if ($val->kindOf() == "array") { foreach ($val as $x) { - //$ret = $x->arraymem(0); $ret = $x[0]; print "<code>" . $ret->scalarval() . " " . $methodName->scalarval() . "("; if ($x->count() > 1) { for ($k = 1; $k < $x->count(); $k++) { - //$y = $x->arraymem($k); $y = $x[$k]; print $y->scalarval(); if ($k < $x->count() - 1) { diff --git a/demo/server/server.php b/demo/server/server.php index d060d977..b18cf467 100644 --- a/demo/server/server.php +++ b/demo/server/server.php @@ -43,7 +43,7 @@ class xmlrpcServerMethodsContainer 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')); + return new PhpXmlRpc\Response(new Value(1, Value::$xmlrpcBoolean)); } /** @@ -222,7 +222,7 @@ function addTwo($req) $s = $req->getParam(0); $t = $req->getParam(1); - return new PhpXmlRpc\Response(new Value($s->scalarval() + $t->scalarval(), "int")); + return new PhpXmlRpc\Response(new Value($s->scalarval() + $t->scalarval(), Value::$xmlrpcInt)); } $addtwodouble_sig = array(array(Value::$xmlrpcDouble, Value::$xmlrpcDouble, Value::$xmlrpcDouble)); @@ -232,7 +232,7 @@ function addTwoDouble($req) $s = $req->getParam(0); $t = $req->getParam(1); - return new PhpXmlRpc\Response(new Value($s->scalarval() + $t->scalarval(), "double")); + return new PhpXmlRpc\Response(new Value($s->scalarval() + $t->scalarval(), Value::$xmlrpcDouble)); } $stringecho_sig = array(array(Value::$xmlrpcString, Value::$xmlrpcString)); @@ -261,7 +261,7 @@ function echoSixtyFour($req) // This is to test that base64 encoding is working as expected $incoming = $req->getParam(0); - return new PhpXmlRpc\Response(new Value($incoming->scalarval(), "string")); + return new PhpXmlRpc\Response(new Value($incoming->scalarval(), Value::$xmlrpcString)); } $bitflipper_sig = array(array(Value::$xmlrpcArray, Value::$xmlrpcArray)); @@ -273,9 +273,9 @@ function bitFlipper($req) foreach ($v as $b) { if ($b->scalarval()) { - $rv->addScalar(false, "boolean"); + $rv[] = new Value(false, Value::$xmlrpcBoolean); } else { - $rv->addScalar(true, "boolean"); + $rv[] = new Value(true, Value::$xmlrpcBoolean); } } @@ -327,37 +327,40 @@ function ageSorter($req) $sno = $req->getParam(0); // error string for [if|when] things go wrong $err = ""; - // create the output value - $v = new Value(); $agar = array(); $max = $sno->count(); PhpXmlRpc\Server::xmlrpc_debugmsg("Found $max array elements"); - foreach ($sno as $rec) { + foreach ($sno as $i => $rec) { 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 = $rec["name"]; + $a = $rec["age"]; // $n and $a are xmlrpcvals, // so get the scalarval from them $agar[$n->scalarval()] = $a->scalarval(); } + // create the output value + $v = new Value(array(), Value::$xmlrpcArray); + $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"); + $v[] = new Value( + array( + "name" => new Value($key), + "age" => new Value($val, "int") + ), + Value::$xmlrpcStruct + ); } - // add this array to the output value - $v->addArray($outAr); if ($err) { return new PhpXmlRpc\Response(0, PhpXmlRpc\PhpXmlRpc::$xmlrpcerruser, $err); @@ -430,7 +433,7 @@ function mailSend($req) if ($err) { return new PhpXmlRpc\Response(0, PhpXmlRpc\PhpXmlRpc::$xmlrpcerruser, $err); } else { - return new PhpXmlRpc\Response(new Value("true", Value::$xmlrpcBoolean)); + return new PhpXmlRpc\Response(new Value(true, Value::$xmlrpcBoolean)); } } @@ -467,7 +470,7 @@ function setCookies($req) setcookie($name, @$cookieDesc['value'], @$cookieDesc['expires'], @$cookieDesc['path'], @$cookieDesc['domain'], @$cookieDesc['secure']); } - return new PhpXmlRpc\Response(new Value(1, 'int')); + return new PhpXmlRpc\Response(new Value(1, Value::$xmlrpcInt)); } $getcookies_sig = array(array(Value::$xmlrpcStruct)); @@ -492,7 +495,7 @@ function v1_arrayOfStructs($req) } } - return new PhpXmlRpc\Response(new Value($numCurly, "int")); + return new PhpXmlRpc\Response(new Value($numCurly, Value::$xmlrpcInt)); } $v1_easyStruct_sig = array(array(Value::$xmlrpcInt, Value::$xmlrpcStruct)); @@ -500,12 +503,12 @@ $v1_easyStruct_doc = 'This handler takes a single parameter, a struct, containin function v1_easyStruct($req) { $sno = $req->getParam(0); - $moe = $sno->structmem("moe"); - $larry = $sno->structmem("larry"); - $curly = $sno->structmem("curly"); + $moe = $sno["moe"]; + $larry = $sno["larry"]; + $curly = $sno["curly"]; $num = $moe->scalarval() + $larry->scalarval() + $curly->scalarval(); - return new PhpXmlRpc\Response(new Value($num, "int")); + return new PhpXmlRpc\Response(new Value($num, Value::$xmlrpcInt)); } $v1_echoStruct_sig = array(array(Value::$xmlrpcStruct, Value::$xmlrpcStruct)); @@ -525,14 +528,16 @@ $v1_manyTypes_sig = array(array( $v1_manyTypes_doc = 'This handler takes six parameters, and returns an array containing all the parameters.'; function v1_manyTypes($req) { - return new PhpXmlRpc\Response(new Value(array( - $req->getParam(0), - $req->getParam(1), - $req->getParam(2), - $req->getParam(3), - $req->getParam(4), - $req->getParam(5),), - "array" + return new PhpXmlRpc\Response(new Value( + array( + $req->getParam(0), + $req->getParam(1), + $req->getParam(2), + $req->getParam(3), + $req->getParam(4), + $req->getParam(5) + ), + Value::$xmlrpcArray )); } @@ -542,13 +547,11 @@ function v1_moderateSizeArrayCheck($req) { $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")); + $last->scalarval(), Value::$xmlrpcString)); } $v1_simpleStructReturn_sig = array(array(Value::$xmlrpcStruct, Value::$xmlrpcInt)); @@ -558,11 +561,13 @@ function v1_simpleStructReturn($req) $sno = $req->getParam(0); $v = $sno->scalarval(); - 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" + return new PhpXmlRpc\Response(new Value( + array( + "times10" => new Value($v * 10, Value::$xmlrpcInt), + "times100" => new Value($v * 100, Value::$xmlrpcInt), + "times1000" => new Value($v * 1000, Value::$xmlrpcInt) + ), + Value::$xmlrpcStruct )); } @@ -572,14 +577,14 @@ function v1_nestedStruct($req) { $sno = $req->getParam(0); - $twoK = $sno->structmem("2000"); - $april = $twoK->structmem("04"); - $fools = $april->structmem("01"); - $curly = $fools->structmem("curly"); - $larry = $fools->structmem("larry"); - $moe = $fools->structmem("moe"); + $twoK = $sno["2000"]; + $april = $twoK["04"]; + $fools = $april["01"]; + $curly = $fools["curly"]; + $larry = $fools["larry"]; + $moe = $fools["moe"]; - return new PhpXmlRpc\Response(new Value($curly->scalarval() + $larry->scalarval() + $moe->scalarval(), "int")); + return new PhpXmlRpc\Response(new Value($curly->scalarval() + $larry->scalarval() + $moe->scalarval(), Value::$xmlrpcInt)); } $v1_countTheEntities_sig = array(array(Value::$xmlrpcStruct, Value::$xmlrpcString)); @@ -616,13 +621,15 @@ function v1_countTheEntities($req) } } - 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" + return new PhpXmlRpc\Response(new Value( + array( + "ctLeftAngleBrackets" => new Value($lt, Value::$xmlrpcInt), + "ctRightAngleBrackets" => new Value($gt, Value::$xmlrpcInt), + "ctAmpersands" => new Value($amp, Value::$xmlrpcInt), + "ctApostrophes" => new Value($ap, Value::$xmlrpcInt), + "ctQuotes" => new Value($qu, Value::$xmlrpcInt) + ), + Value::$xmlrpcStruct )); } diff --git a/src/Client.php b/src/Client.php index e91ec51c..8fce7045 100644 --- a/src/Client.php +++ b/src/Client.php @@ -1059,25 +1059,20 @@ class Client } $response = array(); - //for ($i = 0; $i < $numRets; $i++) { foreach($rets as $val) { - //$val = $rets->arraymem($i); switch ($val->kindOf()) { case 'array': if ($val->count() != 1) { return false; // Bad value } // Normal return value - //$response[] = new Response($val->arraymem(0)); $response[] = new Response($val[0]); break; case 'struct': - //$code = $val->structmem('faultCode'); $code = $val['faultCode']; if ($code->kindOf() != 'scalar' || $code->scalartyp() != 'int') { return false; } - //$str = $val->structmem('faultString'); $str = $val['faultString']; if ($str->kindOf() != 'scalar' || $str->scalartyp() != 'string') { return false; diff --git a/src/Encoder.php b/src/Encoder.php index 16054184..b9bdb08f 100644 --- a/src/Encoder.php +++ b/src/Encoder.php @@ -71,11 +71,8 @@ class Encoder return $xmlrpcVal->scalarval(); case 'array': - //$size = $xmlrpcVal->count(); $arr = array(); - //for ($i = 0; $i < $size; $i++) { foreach($xmlrpcVal as $value) { - //$arr[] = $this->decode($xmlrpcVal->arraymem($i), $options); $arr[] = $this->decode($value, $options); } @@ -292,8 +289,6 @@ class Encoder case 'methodresponse': $v = &$xmlRpcParser->_xh['value']; if ($xmlRpcParser->_xh['isf'] == 1) { - //$vc = $v->structmem('faultCode'); - //$vs = $v->structmem('faultString'); $vc = $v['faultCode']; $vs = $v['faultString']; $r = new Response(0, $vc->scalarval(), $vs->scalarval()); diff --git a/src/Request.php b/src/Request.php index 5220968f..52a3b975 100644 --- a/src/Request.php +++ b/src/Request.php @@ -330,8 +330,6 @@ class Request if ($xmlRpcParser->_xh['isf']) { /// @todo we should test here if server sent an int and a string, and/or coerce them into such... if ($returnType == 'xmlrpcvals') { - //$errNo_v = $v->structmem('faultCode'); - //$errStr_v = $v->structmem('faultString'); $errNo_v = $v['faultCode']; $errStr_v = $v['faultString']; $errNo = $errNo_v->scalarval(); diff --git a/src/Server.php b/src/Server.php index 9b4c59df..07cfb9b4 100644 --- a/src/Server.php +++ b/src/Server.php @@ -915,7 +915,6 @@ class Server if ($call->kindOf() != 'struct') { return static::_xmlrpcs_multicall_error('notstruct'); } - //$methName = $call->structmem('methodName'); $methName = @$call['methodName']; if (!$methName) { return static::_xmlrpcs_multicall_error('nomethod'); @@ -927,7 +926,6 @@ class Server return static::_xmlrpcs_multicall_error('recursion'); } - //$params = @$call->structmem('params'); $params = @$call['params']; if (!$params) { return static::_xmlrpcs_multicall_error('noparams'); @@ -935,12 +933,9 @@ class Server if ($params->kindOf() != 'array') { return static::_xmlrpcs_multicall_error('notarray'); } - //$numParams = $params->count(); $req = new Request($methName->scalarval()); - //for ($i = 0; $i < $numParams; $i++) { foreach($params as $i => $param) { - //if (!$req->addParam($params->arraymem($i))) { if (!$req->addParam($param)) { $i++; // for error message, we count params from 1 return static::_xmlrpcs_multicall_error(new Response(0, @@ -1003,10 +998,7 @@ class Server // let accept a plain list of php parameters, beside a single xmlrpc msg object if (is_object($req)) { $calls = $req->getParam(0); - //$numCalls = $calls->count(); - //for ($i = 0; $i < $numCalls; $i++) { foreach($calls as $call) { - //$call = $calls->arraymem($i); $result[] = static::_xmlrpcs_multicall_do_call($server, $call); } } else { -- 2.47.0