X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=src%2FEncoder.php;h=220ce88165a353f1f15faf99e3d39497e2ef9a19;hb=b5d242c678774aa0952497d77379f61efad733ec;hp=2955f44eadcaa4cdb7e33aaea8058888a7075965;hpb=7ef47445e3dc236ef5fea0d3ea5bd0492a83d2a2;p=plcapi.git diff --git a/src/Encoder.php b/src/Encoder.php index 2955f44..220ce88 100644 --- a/src/Encoder.php +++ b/src/Encoder.php @@ -4,6 +4,9 @@ namespace PhpXmlRpc; use PhpXmlRpc\Helper\XMLParser; +/** + * A helper class to easily convert between Value objects and php native values + */ class Encoder { /** @@ -39,7 +42,7 @@ class Encoder case 'dateTime.iso8601': $xmlrpcVal->scalar = $val; $xmlrpcVal->type = 'datetime'; - $xmlrpcVal->timestamp = \PhpXmlRpc\Helper\Date::iso8601_decode($val); + $xmlrpcVal->timestamp = \PhpXmlRpc\Helper\Date::iso8601Decode($val); return $xmlrpcVal; case 'base64': @@ -71,15 +74,13 @@ class Encoder return $xmlrpcVal->scalarval(); case 'array': - $size = $xmlrpcVal->arraysize(); $arr = array(); - for ($i = 0; $i < $size; $i++) { - $arr[] = $this->decode($xmlrpcVal->arraymem($i), $options); + foreach($xmlrpcVal as $value) { + $arr[] = $this->decode($value, $options); } return $arr; case 'struct': - $xmlrpcVal->structreset(); // If user said so, try to rebuild php objects for specific struct vals. /// @todo should we raise a warning for class not found? // shall we check for proper subclass of xmlrpc value instead of @@ -88,14 +89,14 @@ class Encoder && class_exists($xmlrpcVal->_php_class) ) { $obj = @new $xmlrpcVal->_php_class(); - while (list($key, $value) = $xmlrpcVal->structeach()) { + foreach ($xmlrpcVal as $key => $value) { $obj->$key = $this->decode($value, $options); } return $obj; } else { $arr = array(); - while (list($key, $value) = $xmlrpcVal->structeach()) { + foreach ($xmlrpcVal as $key => $value) { $arr[$key] = $this->decode($value, $options); } @@ -105,7 +106,7 @@ class Encoder $paramCount = $xmlrpcVal->getNumParams(); $arr = array(); for ($i = 0; $i < $paramCount; $i++) { - $arr[] = $this->decode($xmlrpcVal->getParam($i)); + $arr[] = $this->decode($xmlrpcVal->getParam($i), $options); } return $arr; @@ -230,7 +231,7 @@ class Encoder * * @return mixed false on error, or an instance of either Value, Request or Response */ - public function decode_xml($xmlVal, $options = array()) + public function decodeXml($xmlVal, $options = array()) { // 'guestimate' encoding $valEncoding = XMLParser::guessEncoding('', $xmlVal); @@ -244,8 +245,7 @@ class Encoder if (!in_array($valEncoding, array('UTF-8', 'US-ASCII')) && !XMLParser::hasEncoding($xmlVal)) { if ($valEncoding == 'ISO-8859-1') { $xmlVal = utf8_encode($xmlVal); - } - else { + } else { if (extension_loaded('mbstring')) { $xmlVal = mb_convert_encoding($xmlVal, 'UTF-8', $valEncoding); } else { @@ -292,8 +292,8 @@ 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()); } else { $r = new Response($v); @@ -301,12 +301,12 @@ class Encoder return $r; case 'methodcall': - $m = new Request($xmlRpcParser->_xh['method']); + $req = new Request($xmlRpcParser->_xh['method']); for ($i = 0; $i < count($xmlRpcParser->_xh['params']); $i++) { - $m->addParam($xmlRpcParser->_xh['params'][$i]); + $req->addParam($xmlRpcParser->_xh['params'][$i]); } - return $m; + return $req; case 'value': return $xmlRpcParser->_xh['value']; default: