示例#1
0
 public function create_record($values, $model_name)
 {
     $this->client = new xmlrpc_client($this->server_url . 'object');
     //$this->$client->return_type = 'phpvals';
     //   ['execute','userid','password','module.name',{values....}]
     $nval = array();
     foreach ($values as $k => $v) {
         $nval[$k] = new xmlrpcval($v, xmlrpc_get_type($v));
     }
     $msg = new xmlrpcmsg('execute');
     $msg->addParam(new xmlrpcval($this->db, "string"));
     //* database name */
     $msg->addParam(new xmlrpcval($this->uid, "int"));
     /* useid */
     $msg->addParam(new xmlrpcval($this->pass, "string"));
     /** password */
     $msg->addParam(new xmlrpcval($model_name, "string"));
     /** model name where operation will held * */
     $msg->addParam(new xmlrpcval("create", "string"));
     /** method which u like to execute */
     $msg->addParam(new xmlrpcval($nval, "struct"));
     /** parameters of the methods with values....  */
     $resp = $this->client->send($msg);
     return $resp;
     if ($resp->faultCode()) {
         return -1;
     } else {
         return $resp->value();
     }
     /* return new generated id of record */
 }
示例#2
0
function sum($method_name, $params, $app_data)
{
    if (xmlrpc_get_type($params[0]) != "array") {
        return paramfault();
    }
    $sum = 0;
    foreach ($params[0] as $val) {
        if (xmlrpc_get_type($val) != "int") {
            return paramfault();
        }
        $sum = $sum + $val;
    }
    return $sum;
}
示例#3
0
function match($a, $b)
{
    $matches = true;
    if (gettype($a) === "array") {
        foreach ($a as $key => $c) {
            $d = $b[$key];
            if (!match($c, $d)) {
                $matches = false;
                break;
            }
        }
    } else {
        if ($a !== $b || xmlrpc_get_type($a) !== xmlrpc_get_type($b)) {
            $matches = false;
        }
    }
    return $matches;
}
示例#4
0
 /**
  * This method catches any native method called on the client and calls it on the rpc server instead. It automatically
  * parses the resulting xml and returns native php type results.
  * @throws Ripcord_InvalidArgumentException (ripcord::notRipcordCall) when handling a multiCall and the 
  * arguments passed do not have the correct method call information
  * @throws Ripcord_RemoteException when _throwExceptions is true and the server returns an XML-RPC Fault.
  */
 public function __call($name, $args)
 {
     if (isset($this->_namespace)) {
         $name = $this->_namespace . '.' . $name;
     }
     if ($name === 'system.multiCall' || $name == 'system.multicall') {
         if (!$args || is_array($args) && count($args) == 0) {
             // multiCall is called without arguments, so return the fetch interface object
             return new Ripcord_Client_MultiCall($this->_rootClient, $name);
         } else {
             if (is_array($args) && count($args) == 1 && is_array($args[0]) && !isset($args[0]['methodName'])) {
                 // multicall is called with a simple array of calls.
                 $args = $args[0];
             }
         }
         $this->_rootClient->_multiCall = false;
         $params = array();
         $bound = array();
         foreach ($args as $key => $arg) {
             if (!is_a($arg, 'Ripcord_Client_Call') && (!is_array($arg) || !isset($arg['methodName']))) {
                 throw new Ripcord_InvalidArgumentException('Argument ' . $key . ' is not a valid Ripcord call', ripcord::notRipcordCall);
             }
             if (is_a($arg, 'Ripcord_Client_Call')) {
                 $arg->index = count($params);
                 $params[] = $arg->encode();
             } else {
                 $arg['index'] = count($params);
                 $params[] = array('methodName' => $arg['methodName'], 'params' => isset($arg['params']) ? (array) $arg['params'] : array());
             }
             $bound[$key] = $arg;
         }
         $args = array($params);
         $this->_rootClient->_multiCallArgs = array();
     }
     if ($this->_rootClient->_multiCall) {
         $call = new Ripcord_Client_Call($name, $args);
         $this->_rootClient->_multiCallArgs[] = $call;
         return $call;
     }
     if ($this->_rootClient->_cloneObjects) {
         //workaround for php bug 50282
         foreach ($args as $key => $arg) {
             if (is_object($arg)) {
                 $args[$key] = clone $arg;
             }
         }
     }
     $request = xmlrpc_encode_request($name, $args, $this->_outputOptions);
     $response = $this->_transport->post($this->_url, $request);
     $result = xmlrpc_decode($response);
     $this->_rootClient->_request = $request;
     $this->_rootClient->_response = $response;
     if (ripcord::isFault($result) && $this->_throwExceptions) {
         throw new Ripcord_RemoteException($result['faultString'], $result['faultCode']);
     }
     if (isset($bound) && is_array($bound)) {
         foreach ($bound as $key => $callObject) {
             if (is_a($callObject, 'Ripcord_Client_Call')) {
                 $returnValue = $result[$callObject->index];
             } else {
                 $returnValue = $result[$callObject['index']];
             }
             if (is_array($returnValue) && count($returnValue) == 1) {
                 // XML-RPC specification says that non-fault results must be in a single item array
                 $returnValue = current($returnValue);
             }
             if ($this->_autoDecode) {
                 $type = xmlrpc_get_type($returnValue);
                 switch ($type) {
                     case 'base64':
                         $returnValue = ripcord::binary($returnValue);
                         break;
                     case 'datetime':
                         $returnValue = ripcord::timestamp($returnValue);
                         break;
                 }
             }
             if (is_a($callObject, 'Ripcord_Client_Call')) {
                 $callObject->bound = $returnValue;
             }
             $bound[$key] = $returnValue;
         }
         $result = $bound;
     }
     return $result;
 }
示例#5
0
 public function price_get($ids, $product_id, $qty, $partner_id)
 {
     $client = new Client($this->server . "object");
     //   ['execute','userid','password','module.name',{values....}]
     $client->return_type = 'phpvals';
     $id_val = array();
     $count = 0;
     foreach ($ids as $id) {
         $id_val[$count++] = new Value($id, "int");
     }
     $msg = new Request('execute');
     $msg->addParam(new Value($this->database, "string"));
     //* database name */
     $msg->addParam(new Value($this->uid, "int"));
     /* useid */
     $msg->addParam(new Value($this->password, "string"));
     /** password */
     $msg->addParam(new Value('product.pricelist', "string"));
     /** model name where operation will held * */
     $msg->addParam(new Value("price_get", "string"));
     /** method which u like to execute */
     $msg->addParam(new Value($id_val, "array"));
     /** ids of record which to be updting..   this array must be Value array */
     $msg->addParam(new Value($product_id, "int"));
     $msg->addParam(new Value($qty, xmlrpc_get_type($qty)));
     $msg->addParam(new Value($partner_id, "int"));
     $resp = $client->send($msg);
     //print_r($resp);
     if ($resp->faultCode()) {
         return -1;
     } else {
         return $resp->value();
     }
 }
示例#6
0
 /**
  * This method returns the type of the given parameter. This can be any of the XML-RPC data types, e.g.
  * 'struct', 'int', 'string', 'base64', 'boolean', 'double', 'array' or 'datetime'.
  *
  * @param mixed $param
  *
  * @return string
  */
 public static function getType($param)
 {
     return xmlrpc_get_type($param);
 }
示例#7
0
文件: Xmlrpc.php 项目: blar/xmlrpc
 /**
  * @param mixed $value
  * @return string
  */
 public static function getType($value)
 {
     return xmlrpc_get_type($value);
 }
<?php

var_dump(xmlrpc_get_type(new stdclass()));
var_dump(xmlrpc_get_type(array()));
$var = array(1, 2, 3);
var_dump(xmlrpc_get_type($var));
$var = array("test" => 1, 2, 3);
var_dump(xmlrpc_get_type($var));
$var = array("test" => 1, "test2" => 2);
var_dump(xmlrpc_get_type($var));
echo "Done\n";