{"action":"created","issue":{"url":"https://api.github.com/repos/slimphp/Slim/issues/1373","labels_url":"https://api.github.com/repos/slimphp/Slim/issues/1373/labels{/name}","comments_url":"https://api.github.com/repos/slimphp/Slim/issues/1373/comments","events_url":"https://api.github.com/repos/slimphp/Slim/issues/1373/events","html_url":"https://github.com/slimphp/Slim/issues/1373","id":96532035,"number":1373,"title":"Way to add Middleware to ALL routes","user":{"login":"yurevichcv","id":67401,"avatar_url":"https://avatars.githubusercontent.com/u/67401?v=3","gravatar_id":"","url":"https://api.github.com/users/yurevichcv","html_url":"https://github.com/yurevichcv","followers_url":"https://api.github.com/users/yurevichcv/followers","following_url":"https://api.github.com/users/yurevichcv/following{/other_user}","gists_url":"https://api.github.com/users/yurevichcv/gists{/gist_id}","starred_url":"https://api.github.com/users/yurevichcv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yurevichcv/subscriptions","organizations_url":"https://api.github.com/users/yurevichcv/orgs","repos_url":"https://api.github.com/users/yurevichcv/repos","events_url":"https://api.github.com/users/yurevichcv/events{/privacy}","received_events_url":"https://api.github.com/users/yurevichcv/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-07-22T10:34:28Z","updated_at":"2015-07-22T14:55:18Z","closed_at":null,"body":"I'm migrating from Slim 2 to Slim 3 right now and trying to find elegant solution to replace \"slim.before.dispatch\" hook. I used in together with my ACL to check if guest/user has permission to access specific route name this way (simplified version):\r\n```\r\n$app->hook('slim.before.dispatch', function () use ($app, $acl) {\r\n   $route = $app->router()->getCurrentRoute());\r\n   if (!$acl->isAllowed('guest', $route->getName())) {\r\n      //forbidden\r\n   }\r\n}\r\n```\r\n\r\nCurrently I can not use application Middleware, because route is not dispatched yet, and therefore I don't know it's name.\r\n\r\nThe only way I have now is to add same Access Control Middleware to EACH route. This way I will have access to `$request->getAttribute('route')`.\r\n\r\nI guess it should be some straightforward way to add Middleware for ALL routes."},"comment":{"url":"https://api.github.com/repos/slimphp/Slim/issues/comments/123748824","html_url":"https://github.com/slimphp/Slim/issues/1373#issuecomment-123748824","issue_url":"https://api.github.com/repos/slimphp/Slim/issues/1373","id":123748824,"user":{"login":"yurevichcv","id":67401,"avatar_url":"https://avatars.githubusercontent.com/u/67401?v=3","gravatar_id":"","url":"https://api.github.com/users/yurevichcv","html_url":"https://github.com/yurevichcv","followers_url":"https://api.github.com/users/yurevichcv/followers","following_url":"https://api.github.com/users/yurevichcv/following{/other_user}","gists_url":"https://api.github.com/users/yurevichcv/gists{/gist_id}","starred_url":"https://api.github.com/users/yurevichcv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yurevichcv/subscriptions","organizations_url":"https://api.github.com/users/yurevichcv/orgs","repos_url":"https://api.github.com/users/yurevichcv/repos","events_url":"https://api.github.com/users/yurevichcv/events{/privacy}","received_events_url":"https://api.github.com/users/yurevichcv/received_events","type":"User","site_admin":false},"created_at":"2015-07-22T14:55:17Z","updated_at":"2015-07-22T14:55:17Z","body":"This way I will require a lot of this \"if\" statements :) On my opinion this logic of optional routes loading should be handled by groups.\r\n\r\nCurrently main problem of `$app->group` is that it immediately invokes callable. It will be great to implement lazy loading for group callable. This way it will be invoked only during dispatching process and only routes belonging to the group will be loaded."}}