Exemplo n.º 1
0
 /**
  * Handle an incoming request.
  *
  * @param \Illuminate\Http\Request $request
  * @param \Closure                 $next
  *
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     try {
         if ($this->validator->validateRequest($request)) {
             $this->app->singleton('Illuminate\\Contracts\\Debug\\ExceptionHandler', function ($app) {
                 return $app['Dingo\\Api\\Contract\\Debug\\ExceptionHandler'];
             });
             $request = $this->app->make('Dingo\\Api\\Contract\\Http\\Request')->createFromIlluminate($request);
             return $this->sendRequestThroughRouter($request);
         }
     } catch (Exception $exception) {
         return $this->exception->handle($exception);
     }
     return $next($request);
 }
Exemplo n.º 2
0
 /**
  * Prepare a response by transforming and formatting it correctly.
  *
  * @param mixed                   $response
  * @param \Dingo\Api\Http\Request $request
  * @param string                  $format
  *
  * @return \Dingo\Api\Http\Response
  */
 protected function prepareResponse($response, Request $request, $format)
 {
     if ($response instanceof IlluminateResponse) {
         $response = Response::makeFromExisting($response);
     }
     if ($response instanceof Response) {
         // If we try and get a formatter that does not exist we'll let the exception
         // handler deal with it. At worst we'll get a generic JSON response that
         // a consumer can hopefully deal with. Ideally they won't be using
         // an unsupported format.
         try {
             $response->getFormatter($format)->setResponse($response)->setRequest($request);
         } catch (NotAcceptableHttpException $exception) {
             return $this->exception->handle($exception);
         }
         $response = $response->morph($format);
     }
     if ($response->isSuccessful() && $this->requestIsConditional()) {
         if (!$response->headers->has('ETag')) {
             $response->setEtag(md5($response->getContent()));
         }
         $response->isNotModified($request);
     }
     return $response;
 }
Exemplo n.º 3
0
 /**
  * Handle an incoming request.
  *
  * @param \Illuminate\Http\Request $request
  * @param \Closure                 $next
  *
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     try {
         if ($this->validator->validateRequest($request)) {
             $this->app->singleton(LaravelExceptionHandler::class, function ($app) {
                 return $app[ExceptionHandler::class];
             });
             $request = $this->app->make(RequestContract::class)->createFromIlluminate($request);
             $this->events->fire(new RequestWasMatched($request, $this->app));
             return $this->sendRequestThroughRouter($request);
         }
     } catch (Exception $exception) {
         $this->exception->report($exception);
         return $this->exception->handle($exception);
     }
     return $next($request);
 }