X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=src%2FEncoder.php;h=735c3edc12352e02f02bbb2efaf61baceae87668;hb=ac735cf96eb914759f7e7595630857254b599783;hp=86e518e2bdbefcc534930d862b0b500bf90e1e65;hpb=cc67a43993662a5a3f92801b96b89ee6e3998532;p=plcapi.git diff --git a/src/Encoder.php b/src/Encoder.php index 86e518e..735c3ed 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 { /** @@ -33,8 +36,8 @@ class Encoder switch ($xmlrpcVal->kindOf()) { case 'scalar': if (in_array('extension_api', $options)) { - reset($xmlrpcVal->me); - list($typ, $val) = each($xmlrpcVal->me); + $val = reset($xmlrpcVal->me); + $typ = key($xmlrpcVal->me); switch ($typ) { case 'dateTime.iso8601': $xmlrpcVal->scalar = $val; @@ -60,21 +63,20 @@ class Encoder $out = strtotime($out); } if (is_int($out)) { - $result = new \Datetime(); + $result = new \DateTime(); $result->setTimestamp($out); return $result; - } elseif (is_a($out, 'Datetime')) { + } elseif (is_a($out, 'DateTimeInterface')) { return $out; } } return $xmlrpcVal->scalarval(); case 'array': - $size = $xmlrpcVal->count(); $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; @@ -177,12 +179,11 @@ class Encoder case 'object': if (is_a($phpVal, 'PhpXmlRpc\Value')) { $xmlrpcVal = $phpVal; - } elseif (is_a($phpVal, 'DateTime')) { + } elseif (is_a($phpVal, 'DateTimeInterface')) { $xmlrpcVal = new Value($phpVal->format('Ymd\TH:i:s'), Value::$xmlrpcStruct); } else { $arr = array(); - reset($phpVal); - while (list($k, $v) = each($phpVal)) { + foreach($phpVal as $k => $v) { $arr[$k] = $this->encode($v, $options); } $xmlrpcVal = new Value($arr, Value::$xmlrpcStruct); @@ -290,8 +291,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);