Introducing the PHPMinds User Group and how we used middleware for functionality ranging from basic authentication whitelisting to making CLI requests using actions.
'/event-details' ]; if (!isset($_SESSION['auth'])) { if (in_array($request->getUri()->getPath(), $whiteList)) { return $response->withStatus(302)->withHeader('Location', '/'); } } return $next($request, $response); }); Some basic logic to add to the route (or group of routes) Adoni Pavlakis (@pavlakis) - PHPNW16 Uncon
[]; public function __construct(array $session, $authKey = 'auth', array $authRoutes = []) { if (array_key_exists($authKey, $session)) { $this->isAuth = true; } $this->authRoutes = $authRoutes; } public function __invoke(Request $request, Response $response, callable $next) { if (!$this->isAuth) { if (in_array($request->getUri()->getPath(), $this->authRoutes)) { return $response->withStatus(302)->withHeader('Location', '/'); } } return $next($request, $response); } } Move it into its own class