Beispiel #1
0
 /**
  * Returns an instance of the native request object
  *
  * @return mixed
  */
 public function getNativeRequest()
 {
     $method = $this->getMethod();
     $params = $this->getParams();
     switch ($this->getRequestFormat()) {
         case 'local':
             $request = false;
             $request = $this;
             break;
         case 'xmlrpc':
             $request = new Zend_XmlRpc_Request($method, $params);
             break;
         case 'jsonrpc':
             $request = new Zend_Json_Server_Request();
             $request->setMethod($method);
             $request->setParams($params);
             $request->setId('1');
             $request->setVersion('2.0');
             break;
     }
     return $request;
 }
 /**
  * Send an JSON-RPC request to the service (for a specific method)
  *
  * @param  string $method Name of the method we want to call
  * @param  array $params Array of parameters for the method
  * @return mixed
  * @throws Zend_Json_Client_FaultException
  */
 public function call($method, $params = array())
 {
     if (!$this->skipSystemLookup() && !empty($method)) {
         $signature = $this->getIntrospector()->getMethodSignature($method);
         foreach ($params as $key => $param) {
             if (is_int($key)) {
                 // positional parameters
                 // can't validate them
                 continue;
             }
             $keyFound = false;
             foreach ($signature["parameters"] as $parameter) {
                 if ($parameter['name'] == "{$key}") {
                     $keyFound = true;
                 }
             }
             if ($keyFound !== true) {
                 throw new Zend_Json_Client_FaultException("named parameter {$key} not found in SMD");
             }
         }
     }
     $request = new Zend_Json_Server_Request();
     $request->setVersion('2.0');
     $request->setId(1);
     $request->setMethod($method);
     $request->setParams($params);
     $this->doRequest($request);
     if ($this->_lastResponse->isError()) {
         $fault = $this->_lastResponse->getError();
         /**
          * Exception thrown when an JSON-RPC fault is returned
          * @see Zend_Json_Client_FaultException
          */
         require_once 'Zend/Json/Client/FaultException.php';
         throw new Zend_Json_Client_FaultException($fault->getMessage(), $fault->getCode());
     }
     return $this->_lastResponse->getResult();
 }