Example #1
0
 /**
  * Static constructor - start processor
  *
  * @param array|object                           $payload
  * @param \Comodojo\RpcServer\Request\Parameters $parameters
  * @param \Psr\Log\LoggerInterface               $logger
  *
  * @return mixed
  * @throws Exception
  */
 public static function process($payload, Parameters $parameters, \Psr\Log\LoggerInterface $logger)
 {
     try {
         $processor = new JsonProcessor($payload, $parameters, $logger);
         $return = $processor->run();
     } catch (Exception $e) {
         throw $e;
     }
     return $return;
 }
Example #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);
 }