/**
* Takes an xmlrpc value in PHP xmlrpcval object format
* and translates it into native PHP types.
*
* @author Dan Libby ([email protected])
*
* @param xmlrpcval $xmlrpc_val
* @param array $options if 'decode_php_objs' is set in the options array, xmlrpc structs can be decoded into php objects
* @return mixed
*/
function php_xmlrpc_decode($xmlrpc_val, $options = '')
{
$kind = $xmlrpc_val->kindOf();
if ($kind == 'scalar') {
return $xmlrpc_val->scalarval();
} elseif ($kind == 'array') {
$size = $xmlrpc_val->arraysize();
$arr = array();
for ($i = 0; $i < $size; $i++) {
$arr[] = php_xmlrpc_decode($xmlrpc_val->arraymem($i), $options);
}
return $arr;
} elseif ($kind == 'struct') {
$xmlrpc_val->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 xmlrpcval instead of
// presence of _php_class to detect what we can do?
if (@in_array('decode_php_objs', $options) && $xmlrpc_val->_php_class != '' && class_exists($xmlrpc_val->_php_class)) {
$obj = @new $xmlrpc_val->_php_class();
while (list($key, $value) = $xmlrpc_val->structeach()) {
$obj->{$key} = php_xmlrpc_decode($value, $options);
}
return $obj;
} else {
$arr = array();
while (list($key, $value) = $xmlrpc_val->structeach()) {
$arr[$key] = php_xmlrpc_decode($value, $options);
}
return $arr;
}
}
}