{"action":"created","issue":{"url":"https://api.github.com/repos/zendframework/zend-expressive/issues/184","labels_url":"https://api.github.com/repos/zendframework/zend-expressive/issues/184/labels{/name}","comments_url":"https://api.github.com/repos/zendframework/zend-expressive/issues/184/comments","events_url":"https://api.github.com/repos/zendframework/zend-expressive/issues/184/events","html_url":"https://github.com/zendframework/zend-expressive/issues/184","id":116260762,"number":184,"title":"Using $this in route clousure?","user":{"login":"lauthiamkok","id":427931,"avatar_url":"https://avatars.githubusercontent.com/u/427931?v=3","gravatar_id":"","url":"https://api.github.com/users/lauthiamkok","html_url":"https://github.com/lauthiamkok","followers_url":"https://api.github.com/users/lauthiamkok/followers","following_url":"https://api.github.com/users/lauthiamkok/following{/other_user}","gists_url":"https://api.github.com/users/lauthiamkok/gists{/gist_id}","starred_url":"https://api.github.com/users/lauthiamkok/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lauthiamkok/subscriptions","organizations_url":"https://api.github.com/users/lauthiamkok/orgs","repos_url":"https://api.github.com/users/lauthiamkok/repos","events_url":"https://api.github.com/users/lauthiamkok/events{/privacy}","received_events_url":"https://api.github.com/users/lauthiamkok/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":8,"created_at":"2015-11-11T04:09:25Z","updated_at":"2015-11-11T20:22:29Z","closed_at":"2015-11-11T20:22:29Z","body":"I notice that we cannot $this like in Slim 3 in the current version of Expressive\r\n\r\n```\r\n$app->route('/hello/{name}', function ($request, $response, $next) {\r\n    $container = $this->getContainer();\r\n    $name = $request->getAttribute('name');\r\n    $response->getBody()->write('Hello, ' . $name);\r\n    return $response;\r\n});\r\n```\r\n\r\nI will get an an error for that above. I have to pass in $app via use which is not as neat as Slim:\r\n\r\n```\r\n$app->route('/hello/{name}', function ($request, $response, $next)  use ($app) {\r\n    $container = $app->getContainer();\r\n    $name = $request->getAttribute('name');\r\n    $response->getBody()->write('Hello, ' . $name);\r\n    return $response;\r\n});\r\n```\r\n\r\nWould you make that possible in the future versions?"},"comment":{"url":"https://api.github.com/repos/zendframework/zend-expressive/issues/comments/155899737","html_url":"https://github.com/zendframework/zend-expressive/issues/184#issuecomment-155899737","issue_url":"https://api.github.com/repos/zendframework/zend-expressive/issues/184","id":155899737,"user":{"login":"weierophinney","id":25943,"avatar_url":"https://avatars.githubusercontent.com/u/25943?v=3","gravatar_id":"","url":"https://api.github.com/users/weierophinney","html_url":"https://github.com/weierophinney","followers_url":"https://api.github.com/users/weierophinney/followers","following_url":"https://api.github.com/users/weierophinney/following{/other_user}","gists_url":"https://api.github.com/users/weierophinney/gists{/gist_id}","starred_url":"https://api.github.com/users/weierophinney/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/weierophinney/subscriptions","organizations_url":"https://api.github.com/users/weierophinney/orgs","repos_url":"https://api.github.com/users/weierophinney/repos","events_url":"https://api.github.com/users/weierophinney/events{/privacy}","received_events_url":"https://api.github.com/users/weierophinney/received_events","type":"User","site_admin":false},"created_at":"2015-11-11T20:22:29Z","updated_at":"2015-11-11T20:22:29Z","body":"This is not a feature I want to enable.\r\n\r\nOne goal for Expressive is to also encourage best practices. This means using dependency injection, not pulling dependencies from the container within your middleware. If you will be using closures, then you should be passing the app, container, or the actual dependency explicitly; this makes understanding where the instances came from traceable.\r\n\r\nAs @xtreamwayz notes, the `Application` class in Expressive has very little utility beyond registering middleware or retrieving the container; it makes more sense to pass the container explicitly to a closure."}}