Пример #1
0
 /**
  *  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;
 }
Пример #2
0
		/**
		 * Send request to server
		 *
		 * @access private
		 * @param string $command Commend
		 * @param object $params PEAR Params object
		 */
		private function Request($command, $params, $ignorerewrite = false)
		{
			$msg = new XML_RPC_Message($command, $params);
			
			$cache = $this->CacheGet($msg->serialize(), $ignorerewrite);
			if (!$cache)
			{	
				$this->RPClient->setDebug(0);
				$response = $this->RPClient->send($msg);
				
				if (!$response || !$response->faultCode()) 
				{
					try
					{
				    	$val = $response->value();
				    
				    	$retval = XML_RPC_decode($val);
				    	$this->CachePut($msg->serialize(), $retval);
				    }
					catch(Exception $e)
					{
						return false;
					}
					
				    return $retval;
				} 
				else 
				{
				    /*
				     * Display problems that have been gracefully cought and
				     * reported by the xmlrpc.php script
				     */			    
				    throw new Exception(_("RPC Fail")."(".$response->faultCode().") ".$response->faultString());
				}
			}
			else 
				return $cache;
		}