/** * Exec a single request * * @param string $request_method * @param array $parameters * * @return mixed * @throws RpcException */ private function runSingleRequest($request_method, $parameters) { try { $registered_method = $this->checkRequestSustainability($request_method); $selected_signature = $this->checkRequestConsistence($registered_method, $parameters); if (is_array($parameters)) { $parameters = self::matchParameters($parameters, $registered_method, $selected_signature); } $this->parameters->setParameters($parameters); $callback = $registered_method->getCallback(); $method = $registered_method->getMethod(); } catch (RpcException $re) { throw $re; } set_error_handler(function ($severity, $message, $file, $line) { $this->logger->error($message, array("FILE" => $file, "LINE" => $line)); throw new RpcException('Internal error', -32603); }); try { $return = empty($method) ? call_user_func($callback, $this->parameters) : call_user_func(array($callback, $method), $this->parameters); } catch (RpcException $re) { restore_error_handler(); throw $re; } catch (Exception $e) { restore_error_handler(); $this->logger->error($e->getMessage(), array("FILE" => $e->getFile(), "LINE" => $e->getLine())); throw new RpcException('Internal error', -32603); } restore_error_handler(); return $return; }
/** * Class constructor * * @param array $payload * @param \Comodojo\RpcServer\Request\Parameters $parameters * @param \Psr\Log\LoggerInterface $logger */ public function __construct($payload, Parameters $parameters, \Psr\Log\LoggerInterface $logger) { $this->logger = $logger; $this->logger->notice("Starting XML processor"); try { $this->parameters = $parameters; list($this->method, $request_parameters) = self::preprocessRequest($payload); $this->logger->debug("Current request", array('METHOD' => $this->method, 'PARAMS' => $request_parameters)); $this->registered_method = $this->checkRequestSustainability(); $this->selected_signature = $this->checkRequestConsistence($request_parameters); $parameters = self::matchParameters($request_parameters, $this->registered_method, $this->selected_signature); $this->parameters->setParameters($parameters); } catch (RpcException $re) { $this->logger->warning($re->getMessage()); throw $re; } catch (Exception $e) { $this->logger->error($e->getMessage()); throw $e; } }