Beispiel #1
0
 public static function timestamp($datetime)
 {
     try {
         return ripcord::timestamp($datetime);
     } catch (Ripcord_Exception $e) {
         return new ar_error($e->getMessage(), $e->getCode());
     }
 }
Beispiel #2
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;
 }