示例#1
0
 /**
  * @param Request    $request
  * @param RpcRequest $rpcRequest
  *
  * @return RpcResponse|RpcXResponse
  */
 public function dispatchAction(Request $request, RpcRequest $rpcRequest)
 {
     /** @var RequestFactory $requestFactory */
     $requestFactory = $this->get('ms.rpc.request_factory');
     /** @var ResponseFactory $responseFactory */
     $responseFactory = $this->get('ms.rpc.response_factory');
     if ($rpcRequest instanceof RpcXRequest) {
         $service = $rpcRequest->getService();
         $method = $rpcRequest->getMethod();
     } else {
         $method = $rpcRequest->getMethod();
         list($service, $method) = explode(':', $method);
     }
     $service = $this->container->get($service);
     $method = new \ReflectionMethod($service, $method);
     $params = $rpcRequest->getParams();
     $params = $requestFactory->mapParams($method, $params);
     try {
         $result = $method->invokeArgs($service, $params);
         /* @TODO: remove json_encode/json_decode circular reference hack */
         $result = json_encode($result);
         $result = json_decode($result, true);
     } catch (\Exception $result) {
     }
     $rpcResponse = $responseFactory->createFrom($request, $rpcRequest, $result);
     return $rpcResponse;
 }
 /**
  * @param RpcRequest $rpcRequest
  *
  * @return string
  */
 public function getRouteName(RpcRequest $rpcRequest)
 {
     $method = $rpcRequest->getMethod();
     if ($rpcRequest instanceof RpcXRequest) {
         $method = $rpcRequest->getService() . ':' . $method;
     }
     return $method;
 }