Пример #1
0
 /**
  * Perform a single call
  *
  * @param array                                  $request
  * @param \Comodojo\RpcServer\Request\Parameters $parameters_object
  *
  * @return mixed
  */
 private static function singleCall($request, $parameters_object)
 {
     if (!isset($request[0]) || !isset($request[1])) {
         return self::packError(-32600, $parameters_object->errors()->get(-32600));
     }
     if ($request[0] == 'system.multicall') {
         return self::packError(-31001, $parameters_object->errors()->get(-31001));
     }
     $payload = array($request[0], $request[1]);
     try {
         $result = XmlProcessor::process($payload, $parameters_object, $parameters_object->logger());
     } catch (RpcException $re) {
         return self::packError($re->getCode(), $re->getMessage());
     } catch (Exception $e) {
         return self::packError(-32500, $re->getMessage());
     }
     return $result;
 }
Пример #2
0
 /**
  * Serve request
  *
  * @return string
  * @throws Exception
  */
 public function serve()
 {
     $this->logger->notice("Start serving request");
     $parameters_object = new Parameters($this->capabilities, $this->methods, $this->errors, $this->logger, $this->protocol);
     try {
         $this->logger->debug("Received payload: " . $this->payload);
         $payload = $this->uncan($this->payload);
         $this->logger->debug("Decoded payload", (array) $payload);
         if ($this->protocol == self::XMLRPC) {
             $result = XmlProcessor::process($payload, $parameters_object, $this->logger);
         } else {
             if ($this->protocol == self::JSONRPC) {
                 $result = JsonProcessor::process($payload, $parameters_object, $this->logger);
             } else {
                 throw new Exception('Invalid or unsupported RPC protocol');
             }
         }
     } catch (RpcException $re) {
         return $this->can($re, true);
     } catch (Exception $e) {
         throw $e;
     }
     return $this->can($result, false);
 }