Hello, how can I get the current router?
Since determineRouteBeforeAppMiddleware
was removed in v4.
1 Like
maybe this example will help you
LoginauthMiddleware = function($request, $handler): ResponseInterface {
$routeContext = RouteContext::fromRequest($request);
$route = $routeContext->getRoute();
if(empty($route)) { throw new NotFoundException($request, $response); }
$routeName = $route->getName();
$groups = $route->getGroups();
$methods = $route->getMethods();
$arguments = $route->getArguments();
$publicRoutesArray = array('login', 'allow');
if(empty($_SESSION['user']) && (!in_array($routeName, $publicRoutesArray))) {
header("HTTP/1.1 302 Found");
return $response->withRedirect('login');
} else { $response = $handler->handle($request); }
return $response;
};
2 Likes
Very nice, thanks!
1 Like
@slinz You are the genius man. Thanks for i really work like charm.