summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--includes/xmlrpc.inc58
1 files changed, 38 insertions, 20 deletions
diff --git a/includes/xmlrpc.inc b/includes/xmlrpc.inc
index 2418ad7..119ca4b 100644
--- a/includes/xmlrpc.inc
+++ b/includes/xmlrpc.inc
@@ -30,27 +30,43 @@ function xmlrpc_value($data, $type = FALSE) {
return $xmlrpc_value;
}
+/**
+ * Map PHP type to XML-RPC type.
+ *
+ * @param $xmlrpc_value
+ * Variable whose type should be mapped.
+ * @return
+ * XML-RPC type as string.
+ * @see
+ * http://www.xmlrpc.com/spec#scalars
+ */
function xmlrpc_value_calculate_type(&$xmlrpc_value) {
- $type = gettype($xmlrpc_value->data);
- switch ($type) {
- case 'boolean': case 'double':
- return $type;
- case 'integer':
+ // http://www.php.net/gettype: Never use gettype() to test for a certain type [...] Instead, use the is_* functions.
+ if (is_bool($xmlrpc_value->data)) {
+ return 'boolean';
+ }
+ if (is_double($xmlrpc_value->data)) {
+ return 'double';
+ }
+ if (is_int($xmlrpc_value->data)) {
return 'int';
- case 'array':
- return range(0, count($xmlrpc_value->data) - 1) === array_keys($xmlrpc_value->data) ? 'array' : 'struct';
- case 'object':
- if ($xmlrpc_value->data->is_date) {
- return 'date';
- }
- if ($xmlrpc_value->data->is_base64) {
- return 'base64';
- }
- $xmlrpc_value->data = get_object_vars($xmlrpc_value->data);
- return 'struct';
- default:
- return 'string';
}
+ if (is_array($xmlrpc_value->data)) {
+ // empty or integer-indexed arrays are 'array', string-indexed arrays 'struct'
+ return empty($xmlrpc_value->data) || range(0, count($xmlrpc_value->data) - 1) === array_keys($xmlrpc_value->data) ? 'array' : 'struct';
+ }
+ if (is_object($xmlrpc_value->data)) {
+ if ($xmlrpc_value->data->is_date) {
+ return 'date';
+ }
+ if ($xmlrpc_value->data->is_base64) {
+ return 'base64';
+ }
+ $xmlrpc_value->data = get_object_vars($xmlrpc_value->data);
+ return 'struct';
+ }
+ // default
+ return 'string';
}
function xmlrpc_value_get_xml($xmlrpc_value) {
@@ -232,11 +248,13 @@ function xmlrpc_message_tag_close($parser, $tag) {
if ($xmlrpc_message->array_structs_types[count($xmlrpc_message->array_structs_types)-1] == 'struct') {
// Add to struct
$xmlrpc_message->array_structs [count($xmlrpc_message->array_structs )-1][$xmlrpc_message->current_struct_name[count($xmlrpc_message->current_struct_name)-1]] = $value;
- } else {
+ }
+ else {
// Add to array
$xmlrpc_message->array_structs [count($xmlrpc_message->array_structs )-1][] = $value;
}
- } else {
+ }
+ else {
// Just add as a paramater
$xmlrpc_message->params[] = $value;
}