{"action":"created","issue":{"url":"https://api.github.com/repos/symfony/symfony/issues/16968","labels_url":"https://api.github.com/repos/symfony/symfony/issues/16968/labels{/name}","comments_url":"https://api.github.com/repos/symfony/symfony/issues/16968/comments","events_url":"https://api.github.com/repos/symfony/symfony/issues/16968/events","html_url":"https://github.com/symfony/symfony/issues/16968","id":121734628,"number":16968,"title":"[Console] router:match and expression language's condition breaks when using request variable","user":{"login":"ymarillet","id":2027018,"avatar_url":"https://avatars.githubusercontent.com/u/2027018?v=3","gravatar_id":"","url":"https://api.github.com/users/ymarillet","html_url":"https://github.com/ymarillet","followers_url":"https://api.github.com/users/ymarillet/followers","following_url":"https://api.github.com/users/ymarillet/following{/other_user}","gists_url":"https://api.github.com/users/ymarillet/gists{/gist_id}","starred_url":"https://api.github.com/users/ymarillet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ymarillet/subscriptions","organizations_url":"https://api.github.com/users/ymarillet/orgs","repos_url":"https://api.github.com/users/ymarillet/repos","events_url":"https://api.github.com/users/ymarillet/events{/privacy}","received_events_url":"https://api.github.com/users/ymarillet/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/symfony/symfony/labels/Bug","name":"Bug","color":"e10c02"},{"url":"https://api.github.com/repos/symfony/symfony/labels/FrameworkBundle","name":"FrameworkBundle","color":"DDDDDD"},{"url":"https://api.github.com/repos/symfony/symfony/labels/Status:%20Needs%20Review","name":"Status: Needs Review","color":"ededed"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-12-11T15:53:04Z","updated_at":"2016-01-26T01:42:14Z","closed_at":null,"body":"Hi there\r\n\r\nHaving a route defined like this\r\n\r\n```php\r\nclass MyController extends Controller\r\n{\r\n    /**\r\n     * @Route(\r\n     *     \"/mycontroller/{type}\",\r\n     *     name=\"my_route\",\r\n     *     condition=\"service('myservice').isKnownType(request.get('type'))\"\r\n     * )\r\n     */\r\n    public function testAction($type)\r\n    {\r\n        //do something here\r\n    }\r\n}\r\n```\r\n\r\nMakes the router:match to go crazy because the Request object is unknown to the command line\r\n```console\r\napp/console router:matches /mycontroller/supertype\r\n```\r\n\r\n[RuntimeException]\r\n  Unable to get a property on a non-object.\r\n\r\nI believe that a request object should be created here. This is also a very simple example that could have a workaround, but this is not a discussion about that.\r\n\r\nNote: the service function used in the expression language is an implementation of a custom expression language function, which is just returning a defined service\r\n![ya rly](https://i.imgur.com/ttASWYC.gif)"},"comment":{"url":"https://api.github.com/repos/symfony/symfony/issues/comments/174763183","html_url":"https://github.com/symfony/symfony/issues/16968#issuecomment-174763183","issue_url":"https://api.github.com/repos/symfony/symfony/issues/16968","id":174763183,"user":{"login":"paradajozsef","id":3610051,"avatar_url":"https://avatars.githubusercontent.com/u/3610051?v=3","gravatar_id":"","url":"https://api.github.com/users/paradajozsef","html_url":"https://github.com/paradajozsef","followers_url":"https://api.github.com/users/paradajozsef/followers","following_url":"https://api.github.com/users/paradajozsef/following{/other_user}","gists_url":"https://api.github.com/users/paradajozsef/gists{/gist_id}","starred_url":"https://api.github.com/users/paradajozsef/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/paradajozsef/subscriptions","organizations_url":"https://api.github.com/users/paradajozsef/orgs","repos_url":"https://api.github.com/users/paradajozsef/repos","events_url":"https://api.github.com/users/paradajozsef/events{/privacy}","received_events_url":"https://api.github.com/users/paradajozsef/received_events","type":"User","site_admin":false},"created_at":"2016-01-26T01:42:14Z","updated_at":"2016-01-26T01:42:14Z","body":"I confirm this in 2.7, 2.8 and 3.0.  Strace is like:\r\n\r\n1. RouterMatcherCommand [gets traces](https://github.com/symfony/symfony/blob/2.7/src/Symfony/Bundle/FrameworkBundle/Command/RouterMatchCommand.php#L92) from TraceableUrlMatcher\r\n2. TraceableUrlMatcher [matches pathinfo](https://github.com/symfony/symfony/blob/2.7/src/Symfony/Component/Routing/Matcher/TraceableUrlMatcher.php#L36)\r\n3. match() tries to [match pathinfo by route collection](https://github.com/symfony/symfony/blob/2.7/src/Symfony/Component/Routing/Matcher/UrlMatcher.php#L92)\r\n4. TraceableUrlMatcher::matchCollection() [passes request to expression language](https://github.com/symfony/symfony/blob/2.7/src/Symfony/Component/Routing/Matcher/TraceableUrlMatcher.php#L98)\r\n5. But ```$request``` property in ```UrlMatcher``` is set [only in UrlMatcher::matchRequest()](https://github.com/symfony/symfony/blob/2.7/src/Symfony/Component/Routing/Matcher/UrlMatcher.php#L106)\r\n\r\nI think ```$request``` should be passed because it makes kind of useless the router:match command if there is at least one route condition with request.\r\n\r\nStatus: Reviewed"}}