xmlrpc_value_calculate_type

function xmlrpc_value_calculate_type

xmlrpc_value_calculate_type($xmlrpc_value)

Maps a PHP type to an XML-RPC type.

Parameters

$xmlrpc_value: Variable whose type should be mapped.

Return value

string The corresponding XML-RPC type.

See also

http://www.xmlrpc.com/spec#scalars

File

includes/xmlrpc.inc, line 57
Drupal XML-RPC library.

Code

function xmlrpc_value_calculate_type($xmlrpc_value) {
  // 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';
  }
  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 (isset($xmlrpc_value->data->is_date)) {
      return 'date';
    }
    if (isset($xmlrpc_value->data->is_base64)) {
      return 'base64';
    }
    $xmlrpc_value->data = get_object_vars($xmlrpc_value->data);
    return 'struct';
  }
  // default
  return 'string';
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/includes!xmlrpc.inc/function/xmlrpc_value_calculate_type/7.x

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部