當前位置: 首頁>>代碼示例>>PHP>>正文


PHP XML_RPC_Value::addScalar方法代碼示例

本文整理匯總了PHP中XML_RPC_Value::addScalar方法的典型用法代碼示例。如果您正苦於以下問題:PHP XML_RPC_Value::addScalar方法的具體用法?PHP XML_RPC_Value::addScalar怎麽用?PHP XML_RPC_Value::addScalar使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在XML_RPC_Value的用法示例。


在下文中一共展示了XML_RPC_Value::addScalar方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: XML_RPC_encode

/**
 * Converts native PHP types into an XML_RPC_Value object
 *
 * @param mixed $php_val  the PHP value or variable you want encoded
 *
 * @return object  the XML_RPC_Value object
 */
function XML_RPC_encode($php_val)
{
    $type = gettype($php_val);
    $XML_RPC_val = new XML_RPC_Value();
    switch ($type) {
        case 'array':
            if (empty($php_val)) {
                $XML_RPC_val->addArray($php_val);
                break;
            }
            $tmp = array_diff(array_keys($php_val), range(0, count($php_val) - 1));
            if (empty($tmp)) {
                $arr = array();
                foreach ($php_val as $k => $v) {
                    $arr[$k] = XML_RPC_encode($v);
                }
                $XML_RPC_val->addArray($arr);
                break;
            }
            // fall though if it's not an enumerated array
        // fall though if it's not an enumerated array
        case 'object':
            $arr = array();
            foreach ($php_val as $k => $v) {
                $arr[$k] = XML_RPC_encode($v);
            }
            $XML_RPC_val->addStruct($arr);
            break;
        case 'integer':
            $XML_RPC_val->addScalar($php_val, $GLOBALS['XML_RPC_Int']);
            break;
        case 'double':
            $XML_RPC_val->addScalar($php_val, $GLOBALS['XML_RPC_Double']);
            break;
        case 'string':
        case 'NULL':
            if ($GLOBALS['XML_RPC_func_ereg']('^[0-9]{8}\\T{1}[0-9]{2}\\:[0-9]{2}\\:[0-9]{2}$', $php_val)) {
                $XML_RPC_val->addScalar($php_val, $GLOBALS['XML_RPC_DateTime']);
            } elseif ($GLOBALS['XML_RPC_auto_base64'] && $GLOBALS['XML_RPC_func_ereg']("[^ -~\t\r\n]", $php_val)) {
                // Characters other than alpha-numeric, punctuation, SP, TAB,
                // LF and CR break the XML parser, encode value via Base 64.
                $XML_RPC_val->addScalar($php_val, $GLOBALS['XML_RPC_Base64']);
            } else {
                $XML_RPC_val->addScalar($php_val, $GLOBALS['XML_RPC_String']);
            }
            break;
        case 'boolean':
            // Add support for encoding/decoding of booleans, since they
            // are supported in PHP
            // by <G_Giunta_2001-02-29>
            $XML_RPC_val->addScalar($php_val, $GLOBALS['XML_RPC_Boolean']);
            break;
        case 'unknown type':
        default:
            $XML_RPC_val = false;
    }
    return $XML_RPC_val;
}
開發者ID:peteainsworth,項目名稱:civicrm-4.2.9-drupal,代碼行數:65,代碼來源:RPC.php

示例2: gettype

 function _encode($php_val)
 {
     global $XML_RPC_Boolean, $XML_RPC_Int, $XML_RPC_Double;
     global $XML_RPC_String, $XML_RPC_Array, $XML_RPC_Struct;
     $type = gettype($php_val);
     $xmlrpcval = new XML_RPC_Value();
     switch ($type) {
         case "array":
             reset($php_val);
             $firstkey = key($php_val);
             end($php_val);
             $lastkey = key($php_val);
             reset($php_val);
             if ($firstkey === 0 && is_int($lastkey) && $lastkey + 1 == count($php_val)) {
                 $is_continuous = true;
                 reset($php_val);
                 $size = count($php_val);
                 for ($expect = 0; $expect < $size; $expect++, next($php_val)) {
                     if (key($php_val) !== $expect) {
                         $is_continuous = false;
                         break;
                     }
                 }
                 if ($is_continuous) {
                     reset($php_val);
                     $arr = array();
                     while (list($k, $v) = each($php_val)) {
                         $arr[$k] = $this->_encode($v);
                     }
                     $xmlrpcval->addArray($arr);
                     break;
                 }
             }
             // fall though if not numerical and continuous
         // fall though if not numerical and continuous
         case "object":
             $arr = array();
             while (list($k, $v) = each($php_val)) {
                 $arr[$k] = $this->_encode($v);
             }
             $xmlrpcval->addStruct($arr);
             break;
         case "integer":
             $xmlrpcval->addScalar($php_val, $XML_RPC_Int);
             break;
         case "double":
             $xmlrpcval->addScalar($php_val, $XML_RPC_Double);
             break;
         case "string":
         case "NULL":
             $xmlrpcval->addScalar($php_val, $XML_RPC_String);
             break;
         case "boolean":
             $xmlrpcval->addScalar($php_val, $XML_RPC_Boolean);
             break;
         case "unknown type":
         default:
             return null;
     }
     return $xmlrpcval;
 }
開發者ID:HaldunA,項目名稱:phpwebsite,代碼行數:61,代碼來源:Remote.php

示例3: XML_RPC_encode

/**
 * Converts native PHP types into an XML_RPC_Value object
 *
 * @param mixed $php_val  the PHP value or variable you want encoded
 *
 * @return object  the XML_RPC_Value object
 */
function XML_RPC_encode($php_val)
{
    global $XML_RPC_Boolean, $XML_RPC_Int, $XML_RPC_Double, $XML_RPC_String, $XML_RPC_Array, $XML_RPC_Struct;
    $type = gettype($php_val);
    $XML_RPC_val = new XML_RPC_Value();
    switch ($type) {
        case 'array':
            if (empty($php_val)) {
                $XML_RPC_val->addArray($php_val);
                break;
            }
            $tmp = array_diff(array_keys($php_val), range(0, count($php_val) - 1));
            if (empty($tmp)) {
                $arr = array();
                foreach ($php_val as $k => $v) {
                    $arr[$k] = XML_RPC_encode($v);
                }
                $XML_RPC_val->addArray($arr);
                break;
            }
            // fall though if it's not an enumerated array
        // fall though if it's not an enumerated array
        case 'object':
            $arr = array();
            foreach ($php_val as $k => $v) {
                $arr[$k] = XML_RPC_encode($v);
            }
            $XML_RPC_val->addStruct($arr);
            break;
        case 'integer':
            $XML_RPC_val->addScalar($php_val, $XML_RPC_Int);
            break;
        case 'double':
            $XML_RPC_val->addScalar($php_val, $XML_RPC_Double);
            break;
        case 'string':
        case 'NULL':
            $XML_RPC_val->addScalar($php_val, $XML_RPC_String);
            break;
        case 'boolean':
            // Add support for encoding/decoding of booleans, since they
            // are supported in PHP
            // by <G_Giunta_2001-02-29>
            $XML_RPC_val->addScalar($php_val, $XML_RPC_Boolean);
            break;
        case 'unknown type':
        default:
            $XML_RPC_val = false;
    }
    return $XML_RPC_val;
}
開發者ID:BackupTheBerlios,項目名稱:skyapp,代碼行數:58,代碼來源:RPC.php

示例4: XML_RPC_encode

/**
 * Takes native php types and encodes them into XML_RPC PHP object format.
 *
 * Feature creep -- could support more types via optional type argument.
 *
 * @author Dan Libby <dan@libby.com>
 **/
function XML_RPC_encode($php_val)
{
    global $XML_RPC_Boolean;
    global $XML_RPC_Int;
    global $XML_RPC_Double;
    global $XML_RPC_String;
    global $XML_RPC_Array;
    global $XML_RPC_Struct;
    $type = gettype($php_val);
    $XML_RPC_val = new XML_RPC_Value();
    switch ($type) {
        case "array":
            $keys = array_keys($php_val);
            $count = count($php_val);
            $firstkey = $keys[0];
            $lastkey = $keys[$count - 1];
            if ($firstkey === 0 && is_int($lastkey) && $lastkey + 1 == $count) {
                $is_continuous = true;
                $expected = 0;
                foreach ($keys as $actual) {
                    if ($actual != $expected) {
                        $is_continuous = false;
                        break;
                    }
                    $expected++;
                }
                if ($is_continuous) {
                    $arr = array();
                    foreach ($php_val as $k => $v) {
                        $arr[$k] = XML_RPC_encode($v);
                    }
                    $XML_RPC_val->addArray($arr);
                    break;
                }
            }
            // fall though if not numerical and continuous
        // fall though if not numerical and continuous
        case "object":
            $arr = array();
            foreach ($php_val as $k => $v) {
                $arr[$k] = XML_RPC_encode($v);
            }
            $XML_RPC_val->addStruct($arr);
            break;
        case "integer":
            $XML_RPC_val->addScalar($php_val, $XML_RPC_Int);
            break;
        case "double":
            $XML_RPC_val->addScalar($php_val, $XML_RPC_Double);
            break;
        case "string":
        case "NULL":
            $XML_RPC_val->addScalar($php_val, $XML_RPC_String);
            break;
            // <G_Giunta_2001-02-29>
            // Add support for encoding/decoding of booleans, since they are supported in PHP
        // <G_Giunta_2001-02-29>
        // Add support for encoding/decoding of booleans, since they are supported in PHP
        case "boolean":
            $XML_RPC_val->addScalar($php_val, $XML_RPC_Boolean);
            break;
            // </G_Giunta_2001-02-29>
        // </G_Giunta_2001-02-29>
        case "unknown type":
        default:
            $XML_RPC_val = false;
            break;
    }
    return $XML_RPC_val;
}
開發者ID:valentijnvenus,項目名稱:geocloud,代碼行數:77,代碼來源:RPC.php


注:本文中的XML_RPC_Value::addScalar方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。