Esempio n. 1
0
 /**
  * Run the route action and return the response.
  *
  * @param Request $request
  * @return mixed
  * @throws NotFoundHttpException
  */
 protected function runController(Request $request)
 {
     list($class, $method) = explode('@', $this->action['uses']);
     $parameters = $this->resolveClassMethodDependencies($this->parameters(), $class, $method);
     /**
      * JsonRpc HTTP request interpreter
      */
     $interpreter = new Interpreter($request);
     /**
      * JsonRpc request id
      */
     $requestId = $interpreter->getId();
     if (!method_exists($instance = $this->container->make($class), $method)) {
         $error = ResponseErrorFactory::internalError();
         $responseContent = ResponseContent::buildErrorContent($requestId, $error);
         return new Response($responseContent);
     }
     if ($interpreter->hasErrors()) {
         $responseContent = ResponseContent::buildErrorContent($requestId, $interpreter->getFirstError());
         return new Response($responseContent);
     }
     if (null === $requestId) {
         /**
          * The JSON-RPC request is a notification
          * Send an empty response
          *
          * @see http://www.jsonrpc.org/specification#notification
          */
         return new Response();
     }
     try {
         $proxyAlias = 'multirouting.adapters.jsonrpc.request.proxy';
         if ($this->container->bound($proxyAlias)) {
             /** @var ProxyInterface $proxyInstance */
             $proxyInstance = $this->container->make($proxyAlias);
             $proxyInstance->setMatchedInstance($instance);
             $proxyInstance->setMatchedMethod($method);
             $proxyInstance->setMatchedParameters($parameters);
             $instance = $proxyInstance;
         }
     } catch (\Exception $e) {
         $error = ResponseErrorFactory::serverError();
         $responseContent = ResponseContent::buildErrorContent($requestId, $error);
         return new Response($responseContent);
     }
     try {
         $controllerResponse = call_user_func_array([$instance, $method], $parameters);
         $responseContent = ResponseContent::buildSuccessContent($requestId, $controllerResponse);
     } catch (\Exception $e) {
         $error = ResponseErrorFactory::applicationError($e->getCode(), $e->getMessage());
         $responseContent = ResponseContent::buildErrorContent($requestId, $error);
     }
     /**
      * @todo check if the response returned from the controller needs additional headers to be set on the response
      */
     return new Response($responseContent);
 }
Esempio n. 2
0
 /**
  * Run the route action and return the response.
  *
  * @param Request $request
  * @return mixed
  * @throws NotFoundHttpException
  */
 protected function runController(Request $request)
 {
     list($class, $method) = explode('@', $this->action['uses']);
     $parameters = $this->resolveClassMethodDependencies($this->parametersWithoutNulls(), $class, $method);
     if (!method_exists($instance = $this->container->make($class), $method)) {
         throw new NotFoundHttpException();
     }
     /**
      * JsonRpc HTTP request interpreter
      */
     $interpreter = new Interpreter($request);
     /**
      * JsonRpc request id
      */
     $requestId = $interpreter->getId();
     if ($interpreter->hasErrors()) {
         $responseContent = ResponseContent::buildError($requestId, $interpreter->getFirstError());
         return new Response($responseContent);
     }
     if (null === $requestId) {
         // The JSON-RPC request is a notification
         throw new NotificationException();
     }
     try {
         $controllerResponse = call_user_func_array([$instance, $method], $parameters);
         $responseContent = ResponseContent::buildResult($requestId, $controllerResponse);
         //
         //            $error = ResponseErrorFactory::applicationError(
         //                $e->getCode(),
         //                $e->getMessage()
         //            );
         //            $responseContent = ResponseContent::buildError($requestId, $error);
     } catch (\Exception $e) {
         $error = ResponseErrorFactory::serverError();
         $responseContent = ResponseContent::buildError($requestId, $error);
     }
     /**
      * @todo check if the response returned from the controller needs additional headers to be set on the response
      */
     return new Response($responseContent);
 }