authenticator = $authenticator; } /** * Invoke the AuthGuard middleware, throwing an exception if there is no authenticated user in the session. * * @param \Psr\Http\Message\ServerRequestInterface $request PSR7 request * @param \Psr\Http\Message\ResponseInterface $response PSR7 response * @param callable $next Next middleware * * @return \Psr\Http\Message\ResponseInterface */ public function __invoke($request, $response, $next) { if (!$this->authenticator->check()) { throw new AuthExpiredException(); } else { return $next($request, $response); } return $response; } }