コード例 #1
0
 /**
  * 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();
 }
コード例 #2
0
 /**
  * Invoke service
  *
  * @param Invocation $invocation
  * @return mixed
  * @throws InitiallyRpcException
  */
 public function invoke(Invocation $invocation)
 {
     $request = new Request();
     $request->setInterface($this->interface);
     $request->setMethodName($invocation->getMethodName());
     $request->setArguments($invocation->getArguments());
     $transport = Transport::factory($this->config->getTransport());
     if (!$transport instanceof Transport) {
         throw new InitiallyRpcException("missing transport");
     }
     return $transport->send($request);
 }