当前位置: 首页>>代码示例>>PHP>>正文


PHP XML_RPC_Value::addStruct方法代码示例

本文整理汇总了PHP中XML_RPC_Value::addStruct方法的典型用法代码示例。如果您正苦于以下问题:PHP XML_RPC_Value::addStruct方法的具体用法?PHP XML_RPC_Value::addStruct怎么用?PHP XML_RPC_Value::addStruct使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在XML_RPC_Value的用法示例。


在下文中一共展示了XML_RPC_Value::addStruct方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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

示例3: 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

示例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

示例5: callMethod

 /**
  *  XMLRPC methods wrapper
  *  Encode XMLRPC request message, send it, receive and decode response.
  *
  *  @param method string, method name
  *  @param gettedPars array, returned by func_get_args() in called method
  *
  *  @return array, PHP hash with response
  */
 public function callMethod($method, $gettedPars)
 {
     $parr = array();
     $XML_RPC_val = new XML_RPC_Value();
     foreach ($this->mdefs[$method]['p'] as $i => $p) {
         $parr[$p] = new XML_RPC_Value();
         if ($this->mdefs[$method]['t'][$i] == 'array') {
             $parr[$p] = XML_RPC_encode($gettedPars[$i]);
         } else {
             $parr[$p]->addScalar($gettedPars[$i], $this->mdefs[$method]['t'][$i]);
         }
     }
     $XML_RPC_val->addStruct($parr);
     $fullmethod = $this->mdefs[$method]['m'];
     $msg = new XML_RPC_Message($fullmethod, array($XML_RPC_val));
     if ($this->verbose) {
         echo "parr:\n";
         var_dump($parr);
         echo "message:\n";
         echo $msg->serialize() . "\n";
     }
     $this->client->setDebug($this->debug);
     $res = $this->client->send($msg);
     if (!$res) {
         return $this->client->errstr;
     }
     if ($res->faultCode() > 0) {
         return PEAR::raiseError("XR_CcClient::{$method}:" . $res->faultString() . " " . $res->faultCode() . "\n", $res->faultCode(), PEAR_ERROR_RETURN);
     }
     if ($this->verbose) {
         echo "result:\n";
         echo $res->serialize();
     }
     $val = $res->value();
     $resp = XML_RPC_decode($res->value());
     return $resp;
 }
开发者ID:sourcefabric,项目名称:newscoop,代码行数:46,代码来源:XR_CcClient.php

示例6: XML_RPC_Server_system_multiCall

/**
 * Executes multiple methods in sequence and returns the results 
 * (implements http://www.xmlrpc.com/discuss/msgReader$1208)
 *
 * @return object  a new XML_RPC_Response object
 */
function XML_RPC_Server_system_multiCall($server, $msg)
{
    $dmap = $server->dmap;
    $array = $msg;
    for ($i = 0; $i < $array->getNumParams(); $i++) {
        $details = $array->getParam($i);
        if ($details->kindOf() != 'struct') {
            $resp = new XML_RPC_Response(0, $GLOBALS['XML_RPC_err']['incorrect_params'], "system_multiCall() expects _only_ struct datatypes wrapped in one array.");
        } elseif ($details->arraysize() >= 1) {
            // check if method name a string pointing to valid function
            if (!is_a($method_obj = $details->structmem('methodName'), 'XML_RPC_value') || $method_obj->kindOf() != 'scalar' || !($method = $method_obj->scalarVal()) || !strlen($function = $dmap[$method]['function'])) {
                $resp = new XML_RPC_Response(0, $GLOBALS['XML_RPC_err']['incorrect_params'], "system_multiCall() method call '{$method}' type '" . gettype($method) . "' resolves to an invalid function. Parameter or dmap configuration problem?");
            } elseif (($params = $details->structmem('params')) && (!is_a($params, 'XML_RPC_Value') || $params->kindOf() != 'array')) {
                $resp = new XML_RPC_Response(0, $GLOBALS['XML_RPC_err']['incorrect_params'], "system_multiCall() method call '{$function}' parameters container " . "is not a XML_RPC_Value type '{$GLOBALS['XML_RPC_Array']}'.");
            } elseif (preg_match("/\\bsystem_multiCall\$/i", $function)) {
                $resp = new XML_RPC_Response(0, $GLOBALS['XML_RPC_err']['incorrect_params'], "system_multiCall() must not be called recursively.");
            } else {
                // build array containing xml_rpc_value of each param
                $params_list = array();
                for ($j = 0; isset($params) && $j < $params->arraysize(); $j++) {
                    $params_list[] = $param = $params->arraymem($j);
                }
                $msg = new XML_RPC_Message($method, $params_list);
                $msg->setSendEncoding($server->encoding);
                $resp = $server->execute($function, $msg);
            }
        } else {
            $resp = new XML_RPC_Response(0, $GLOBALS['XML_RPC_err']['incorrect_params'], "system_multiCall() must be called with at" . "least the functions name as parameter 1");
        }
        // convert error to struct (multiCall Spec)
        if (!$resp->faultCode()) {
            $xml_response = array();
            $xml_response[] = $resp->value();
            $values[] = new XML_RPC_Value($xml_response, 'array');
            //$values[] = $resp->value();
        } else {
            $value = new XML_RPC_Value();
            $value->addStruct(array('faultCode' => new XML_RPC_Value($resp->faultCode(), $GLOBALS['XML_RPC_Int']), 'faultString' => new XML_RPC_Value($resp->faultString(), $GLOBALS['XML_RPC_String'])));
            $values[] = $value;
        }
    }
    $v = new XML_RPC_Value();
    $v->addArray($values);
    return new XML_RPC_Response($v);
}
开发者ID:sqall01,项目名称:additional_plugins,代码行数:51,代码来源:Server.php


注:本文中的XML_RPC_Value::addStruct方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。