/** * Send Rpc Request * * @param Request $request * @return mixed * @throws InitiallyRpcException */ public function send(Request $request) { $interface = $request->getInterface(); $service = ConfigFactory::getClient()->getService($interface); $url = $service->getUrl(); $requestRaw = Formatter::serialize($request); $responseRaw = $this->protocol->sendData($url, $requestRaw); $response = @Formatter::unserialize($responseRaw); if (!$response instanceof Response) { LoggerProxy::getInstance()->error("illegal response", array($responseRaw)); throw new InitiallyRpcException("illegal response"); } elseif ($response->isHasException()) { $exception = $response->getException(); if (is_object($exception) && $exception instanceof Exception) { throw $exception; } else { if (is_string($exception)) { if (class_exists($exception)) { throw new $exception($response->getExceptionMessage()); } else { throw new InitiallyRpcException($response->getExceptionMessage()); } } } } return $response->getResult(); }
/** * Client constructor. * * @param string $configFile */ public function __construct($configFile) { $this->setAsGlobal(); $this->setConfigFileAndCheck($configFile); $this->config = ConfigFactory::getClient(); $this->isPHP7 = version_compare(PHP_VERSION, "7.0.0", ">="); $this->builder = $this->isPHP7 ? new PHP7Builder() : new PHP5Builder(); }
/** * Server constructor. * * @param string $configFile */ public function __construct($configFile) { $this->setAsGlobal(); $this->setConfigFileAndCheck($configFile); $this->config = ConfigFactory::getServer(); $this->transport = Transport::factory($this->config->getTransport()); $this->protocol = new Protocol(); set_exception_handler(array($this, "exceptionHandler")); }
/** * ClientInvoker constructor. * * @param $interface */ public function __construct($interface) { $this->interface = $interface; $this->config = ConfigFactory::getClient(); }