/** * Handle a given request and return the response. * * @param \Symfony\Component\HttpFoundation\Request $request * @param int $type * @param bool $catch * @return \Symfony\Component\HttpFoundation\Response * @throws \Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException */ public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true) { // Our middleware needs to ensure that Laravel is booted before we // can do anything. This gives us access to all the booted // service providers and other container bindings. $this->container->boot(); if ($request instanceof InternalRequest || $this->auth->user()) { return $this->app->handle($request, $type, $catch); } // If a collection exists for the request and we can match a route // from the request then we'll check to see if the route is // protected and, if it is, we'll attempt to authenticate. if ($this->router->requestTargettingApi($request) && ($collection = $this->getApiRouteCollection($request))) { try { $route = $this->controllerReviser->revise($collection->match($request)); if ($this->routeIsProtected($route)) { return $this->authenticate($request, $route) ?: $this->app->handle($request, $type, $catch); } } catch (HttpExceptionInterface $exception) { // If we catch an HTTP exception then we'll simply let // the wrapping kernel do its thing. } } return $this->app->handle($request, $type, $catch); }
public function testRoutingToRevisedControllerWithUnprotectedMethod() { $reviser = new ControllerReviser(); $route = $reviser->revise(new Route('GET', '/', ['controller' => 'UnprotectedControllerStub@index'])); $this->assertFalse($route->getAction()['protected']); }
/** * Handle the revising of a controller for API requests. * * @param \Illuminate\Routing\Route $route * @param \Illuminate\Http\Request $request * * @return void */ public function handle(Route $route, Request $request) { if ($this->router->isApiRequest($request)) { $this->reviser->revise($route); } }