/** * 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); }
/** * @param Invocation $invocation * @return Response * @throws InitiallyRpcException */ public function invoke(Invocation $invocation) { $methodName = $invocation->getMethodName(); $arguments = $invocation->getArguments(); if (!method_exists($this->target, $methodName)) { throw new InitiallyRpcException("method not exists"); } else { if (empty($arguments)) { $result = call_user_func(array($this->target, $methodName)); } else { $result = call_user_func_array(array($this->target, $methodName), $arguments); } } $response = new Response(); $response->setResult($result); return $response; }