{"action":"created","comment":{"url":"https://api.github.com/repos/symfony/symfony/pulls/comments/58049518","id":58049518,"diff_hunk":"@@ -0,0 +1,123 @@\n+<?php\n+\n+/*\n+ * This file is part of the Symfony package.\n+ *\n+ * (c) Fabien Potencier <fabien@symfony.com>\n+ *\n+ * For the full copyright and license information, please view the LICENSE\n+ * file that was distributed with this source code.\n+ */\n+\n+namespace Symfony\\Component\\HttpKernel\\Tests\\Controller;\n+\n+use Symfony\\Component\\HttpKernel\\Controller\\LegacyArgumentResolver;\n+use Symfony\\Component\\HttpKernel\\Controller\\ControllerResolver;\n+use Symfony\\Component\\HttpKernel\\Tests\\Fixtures\\Controller\\VariadicController;\n+use Symfony\\Component\\HttpFoundation\\Request;\n+\n+class LegacyArgumentResolverTest extends \\PHPUnit_Framework_TestCase\n+{\n+    public function testGetArguments()\n+    {\n+        $resolver = new LegacyArgumentResolver();\n+\n+        $request = Request::create('/');\n+        $controller = array(new self(), 'testGetArguments');\n+        $this->assertEquals(array(), $resolver->getArguments($request, $controller), '->getArguments() returns an empty array if the method takes no arguments');\n+\n+        $request = Request::create('/');\n+        $request->attributes->set('foo', 'foo');\n+        $controller = array(new self(), 'controllerMethod1');\n+        $this->assertEquals(array('foo'), $resolver->getArguments($request, $controller), '->getArguments() returns an array of arguments for the controller method');\n+\n+        $request = Request::create('/');\n+        $request->attributes->set('foo', 'foo');\n+        $controller = array(new self(), 'controllerMethod2');\n+        $this->assertEquals(array('foo', null), $resolver->getArguments($request, $controller), '->getArguments() uses default values if present');\n+\n+        $request->attributes->set('bar', 'bar');\n+        $this->assertEquals(array('foo', 'bar'), $resolver->getArguments($request, $controller), '->getArguments() overrides default values if provided in the request attributes');\n+\n+        $request = Request::create('/');\n+        $request->attributes->set('foo', 'foo');\n+        $controller = function ($foo) {};\n+        $this->assertEquals(array('foo'), $resolver->getArguments($request, $controller));\n+\n+        $request = Request::create('/');\n+        $request->attributes->set('foo', 'foo');\n+        $controller = function ($foo, $bar = 'bar') {};\n+        $this->assertEquals(array('foo', 'bar'), $resolver->getArguments($request, $controller));\n+\n+        $request = Request::create('/');\n+        $request->attributes->set('foo', 'foo');\n+        $controller = new self();\n+        $this->assertEquals(array('foo', null), $resolver->getArguments($request, $controller));\n+        $request->attributes->set('bar', 'bar');\n+        $this->assertEquals(array('foo', 'bar'), $resolver->getArguments($request, $controller));\n+\n+        $request = Request::create('/');\n+        $request->attributes->set('foo', 'foo');\n+        $request->attributes->set('foobar', 'foobar');\n+        $controller = 'Symfony\\Component\\HttpKernel\\Tests\\Controller\\another_controller_function';\n+        $this->assertEquals(array('foo', 'foobar'), $resolver->getArguments($request, $controller));\n+\n+        $request = Request::create('/');\n+        $request->attributes->set('foo', 'foo');\n+        $request->attributes->set('foobar', 'foobar');\n+        $controller = array(new self(), 'controllerMethod3');\n+\n+        try {\n+            $resolver->getArguments($request, $controller);\n+            $this->fail('->getArguments() throws a \\RuntimeException exception if it cannot determine the argument value');\n+        } catch (\\Exception $e) {\n+            $this->assertInstanceOf('\\RuntimeException', $e, '->getArguments() throws a \\RuntimeException exception if it cannot determine the argument value');\n+        }\n+\n+        $request = Request::create('/');\n+        $controller = array(new self(), 'controllerMethod5');\n+        $this->assertEquals(array($request), $resolver->getArguments($request, $controller), '->getArguments() injects the request');\n+    }\n+\n+    /**\n+     * @requires PHP 5.6\n+     */\n+    public function testGetVariadicArguments()\n+    {\n+        $resolver = new ControllerResolver();\n+\n+        $request = Request::create('/');\n+        $request->attributes->set('foo', 'foo');\n+        $request->attributes->set('bar', array('foo', 'bar'));\n+        $controller = array(new VariadicController(), 'action');\n+        $this->assertEquals(array('foo', 'foo', 'bar'), $resolver->getArguments($request, $controller));\n+    }\n+\n+    public function __invoke($foo, $bar = null)\n+    {\n+    }\n+\n+    public function controllerMethod1($foo)\n+    {\n+    }\n+\n+    protected function controllerMethod2($foo, $bar = null)\n+    {\n+    }\n+\n+    protected function controllerMethod3($foo, $bar, $foobar)","path":"src/Symfony/Component/HttpKernel/Tests/Controller/LegacyArgumentResolverTest.php","position":108,"original_position":108,"commit_id":"867ca16be3cea522ae86859a21ee3f3a2fc74068","original_commit_id":"867ca16be3cea522ae86859a21ee3f3a2fc74068","user":{"login":"trousers","id":5161466,"avatar_url":"https://avatars.githubusercontent.com/u/5161466?v=3","gravatar_id":"","url":"https://api.github.com/users/trousers","html_url":"https://github.com/trousers","followers_url":"https://api.github.com/users/trousers/followers","following_url":"https://api.github.com/users/trousers/following{/other_user}","gists_url":"https://api.github.com/users/trousers/gists{/gist_id}","starred_url":"https://api.github.com/users/trousers/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/trousers/subscriptions","organizations_url":"https://api.github.com/users/trousers/orgs","repos_url":"https://api.github.com/users/trousers/repos","events_url":"https://api.github.com/users/trousers/events{/privacy}","received_events_url":"https://api.github.com/users/trousers/received_events","type":"User","site_admin":false},"body":"![Codacy](https://www.codacy.com/assets/images/favicon.png) Issue found: [Avoid unused parameters such as '$foo'.](https://www.codacy.com/app/git_9/symfony/file/2331529211/issues/source?bid=3207821&fileBranchId=3207847#l108)","created_at":"2016-03-31T13:06:29Z","updated_at":"2016-03-31T13:06:29Z","html_url":"https://github.com/symfony/symfony/pull/18308#discussion_r58049518","pull_request_url":"https://api.github.com/repos/symfony/symfony/pulls/18308","_links":{"self":{"href":"https://api.github.com/repos/symfony/symfony/pulls/comments/58049518"},"html":{"href":"https://github.com/symfony/symfony/pull/18308#discussion_r58049518"},"pull_request":{"href":"https://api.github.com/repos/symfony/symfony/pulls/18308"}}},"pull_request":{"url":"https://api.github.com/repos/symfony/symfony/pulls/18308","id":64150123,"html_url":"https://github.com/symfony/symfony/pull/18308","diff_url":"https://github.com/symfony/symfony/pull/18308.diff","patch_url":"https://github.com/symfony/symfony/pull/18308.patch","issue_url":"https://api.github.com/repos/symfony/symfony/issues/18308","number":18308,"state":"open","locked":false,"title":"Added an ArgumentResolver with clean extension point","user":{"login":"iltar","id":1754678,"avatar_url":"https://avatars.githubusercontent.com/u/1754678?v=3","gravatar_id":"","url":"https://api.github.com/users/iltar","html_url":"https://github.com/iltar","followers_url":"https://api.github.com/users/iltar/followers","following_url":"https://api.github.com/users/iltar/following{/other_user}","gists_url":"https://api.github.com/users/iltar/gists{/gist_id}","starred_url":"https://api.github.com/users/iltar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/iltar/subscriptions","organizations_url":"https://api.github.com/users/iltar/orgs","repos_url":"https://api.github.com/users/iltar/repos","events_url":"https://api.github.com/users/iltar/events{/privacy}","received_events_url":"https://api.github.com/users/iltar/received_events","type":"User","site_admin":false},"body":"| Q             | A\r\n| ------------- | ---\r\n| Branch?       | master\r\n| Bug fix?      | no\r\n| New feature?  | yes\r\n| BC breaks?    | no\r\n| Deprecations? | yes\r\n| Tests pass?   | yes (FrameworkBundle fails until merged due to new ~3.1 dependency) \r\n| Fixed tickets | #17933 (pre-work), #1547, #10710\r\n| License       | MIT\r\n| Doc PR        | ~\r\n\r\n**This PR is a follow up for and blocked by: #18187**, relates to #11457 by @WouterJ. When reviewing, please take the last commit: [Added an ArgumentResolver with clean extension point](https://github.com/symfony/symfony/pull/18308/commits/4c092b31f91d6071918c90acf15d0035a2a6d12d)\r\n\r\nThis PR provides:\r\n- The ability to tag your own `ArgumentValueResolverInterface`. This means that you can effectively expand on the argument resolving in the `HttpKernel` without having to implement your own `ArgumentResolver`.\r\n\r\n- The possibility to cache away argument metadata via a new `ArgumentMetadataFactory` which simply fetches the data from the cache, effectively omitting 1 reflection call per request. *Not implemented in this PR, but possible once this is merged.*\r\n\r\n- The possibility to add a PSR-7 adapter to resolve the correct request, avoids the paramconverters\r\n- The possibility to add a value resolver to fetch stuff from $request->query\r\n- Drupal could simplify [their argument resolving](https://github.com/drupal/drupal/blob/8.1.x/core/lib/Drupal/Core/Controller/ControllerResolver.php) by a lot\r\n- etc.\r\n\r\nThe aim for this PR is to provide a 100% BC variant to add argument resolving in a clean way, this is shown by the 2 tests: `LegacyArgumentResolverTest` and `ArgumentResolverTest`. \r\n\r\n/cc @dawehner @larowlan if you have time, can you check the impact for Drupal? I think this should be a very simple change which should make it more maintainable. ","created_at":"2016-03-25T10:25:01Z","updated_at":"2016-03-31T13:06:30Z","closed_at":null,"merged_at":null,"merge_commit_sha":"7967436c51e5f3ddffd92ed5704db726b6e002c7","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/symfony/symfony/pulls/18308/commits","review_comments_url":"https://api.github.com/repos/symfony/symfony/pulls/18308/comments","review_comment_url":"https://api.github.com/repos/symfony/symfony/pulls/comments{/number}","comments_url":"https://api.github.com/repos/symfony/symfony/issues/18308/comments","statuses_url":"https://api.github.com/repos/symfony/symfony/statuses/867ca16be3cea522ae86859a21ee3f3a2fc74068","head":{"label":"iltar:feature/argument-resolver-extention-point","ref":"feature/argument-resolver-extention-point","sha":"867ca16be3cea522ae86859a21ee3f3a2fc74068","user":{"login":"iltar","id":1754678,"avatar_url":"https://avatars.githubusercontent.com/u/1754678?v=3","gravatar_id":"","url":"https://api.github.com/users/iltar","html_url":"https://github.com/iltar","followers_url":"https://api.github.com/users/iltar/followers","following_url":"https://api.github.com/users/iltar/following{/other_user}","gists_url":"https://api.github.com/users/iltar/gists{/gist_id}","starred_url":"https://api.github.com/users/iltar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/iltar/subscriptions","organizations_url":"https://api.github.com/users/iltar/orgs","repos_url":"https://api.github.com/users/iltar/repos","events_url":"https://api.github.com/users/iltar/events{/privacy}","received_events_url":"https://api.github.com/users/iltar/received_events","type":"User","site_admin":false},"repo":{"id":7439250,"name":"symfony","full_name":"iltar/symfony","owner":{"login":"iltar","id":1754678,"avatar_url":"https://avatars.githubusercontent.com/u/1754678?v=3","gravatar_id":"","url":"https://api.github.com/users/iltar","html_url":"https://github.com/iltar","followers_url":"https://api.github.com/users/iltar/followers","following_url":"https://api.github.com/users/iltar/following{/other_user}","gists_url":"https://api.github.com/users/iltar/gists{/gist_id}","starred_url":"https://api.github.com/users/iltar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/iltar/subscriptions","organizations_url":"https://api.github.com/users/iltar/orgs","repos_url":"https://api.github.com/users/iltar/repos","events_url":"https://api.github.com/users/iltar/events{/privacy}","received_events_url":"https://api.github.com/users/iltar/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/iltar/symfony","description":"The Symfony PHP framework","fork":true,"url":"https://api.github.com/repos/iltar/symfony","forks_url":"https://api.github.com/repos/iltar/symfony/forks","keys_url":"https://api.github.com/repos/iltar/symfony/keys{/key_id}","collaborators_url":"https://api.github.com/repos/iltar/symfony/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/iltar/symfony/teams","hooks_url":"https://api.github.com/repos/iltar/symfony/hooks","issue_events_url":"https://api.github.com/repos/iltar/symfony/issues/events{/number}","events_url":"https://api.github.com/repos/iltar/symfony/events","assignees_url":"https://api.github.com/repos/iltar/symfony/assignees{/user}","branches_url":"https://api.github.com/repos/iltar/symfony/branches{/branch}","tags_url":"https://api.github.com/repos/iltar/symfony/tags","blobs_url":"https://api.github.com/repos/iltar/symfony/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/iltar/symfony/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/iltar/symfony/git/refs{/sha}","trees_url":"https://api.github.com/repos/iltar/symfony/git/trees{/sha}","statuses_url":"https://api.github.com/repos/iltar/symfony/statuses/{sha}","languages_url":"https://api.github.com/repos/iltar/symfony/languages","stargazers_url":"https://api.github.com/repos/iltar/symfony/stargazers","contributors_url":"https://api.github.com/repos/iltar/symfony/contributors","subscribers_url":"https://api.github.com/repos/iltar/symfony/subscribers","subscription_url":"https://api.github.com/repos/iltar/symfony/subscription","commits_url":"https://api.github.com/repos/iltar/symfony/commits{/sha}","git_commits_url":"https://api.github.com/repos/iltar/symfony/git/commits{/sha}","comments_url":"https://api.github.com/repos/iltar/symfony/comments{/number}","issue_comment_url":"https://api.github.com/repos/iltar/symfony/issues/comments{/number}","contents_url":"https://api.github.com/repos/iltar/symfony/contents/{+path}","compare_url":"https://api.github.com/repos/iltar/symfony/compare/{base}...{head}","merges_url":"https://api.github.com/repos/iltar/symfony/merges","archive_url":"https://api.github.com/repos/iltar/symfony/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/iltar/symfony/downloads","issues_url":"https://api.github.com/repos/iltar/symfony/issues{/number}","pulls_url":"https://api.github.com/repos/iltar/symfony/pulls{/number}","milestones_url":"https://api.github.com/repos/iltar/symfony/milestones{/number}","notifications_url":"https://api.github.com/repos/iltar/symfony/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/iltar/symfony/labels{/name}","releases_url":"https://api.github.com/repos/iltar/symfony/releases{/id}","deployments_url":"https://api.github.com/repos/iltar/symfony/deployments","created_at":"2013-01-04T11:22:34Z","updated_at":"2015-02-06T10:55:28Z","pushed_at":"2016-03-31T10:37:13Z","git_url":"git://github.com/iltar/symfony.git","ssh_url":"git@github.com:iltar/symfony.git","clone_url":"https://github.com/iltar/symfony.git","svn_url":"https://github.com/iltar/symfony","homepage":"symfony.com","size":70082,"stargazers_count":0,"watchers_count":0,"language":"PHP","has_issues":false,"has_downloads":false,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"symfony:master","ref":"master","sha":"6ed73d56d980434fc3d7c4f3c288eee009db33ea","user":{"login":"symfony","id":143937,"avatar_url":"https://avatars.githubusercontent.com/u/143937?v=3","gravatar_id":"","url":"https://api.github.com/users/symfony","html_url":"https://github.com/symfony","followers_url":"https://api.github.com/users/symfony/followers","following_url":"https://api.github.com/users/symfony/following{/other_user}","gists_url":"https://api.github.com/users/symfony/gists{/gist_id}","starred_url":"https://api.github.com/users/symfony/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/symfony/subscriptions","organizations_url":"https://api.github.com/users/symfony/orgs","repos_url":"https://api.github.com/users/symfony/repos","events_url":"https://api.github.com/users/symfony/events{/privacy}","received_events_url":"https://api.github.com/users/symfony/received_events","type":"Organization","site_admin":false},"repo":{"id":458058,"name":"symfony","full_name":"symfony/symfony","owner":{"login":"symfony","id":143937,"avatar_url":"https://avatars.githubusercontent.com/u/143937?v=3","gravatar_id":"","url":"https://api.github.com/users/symfony","html_url":"https://github.com/symfony","followers_url":"https://api.github.com/users/symfony/followers","following_url":"https://api.github.com/users/symfony/following{/other_user}","gists_url":"https://api.github.com/users/symfony/gists{/gist_id}","starred_url":"https://api.github.com/users/symfony/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/symfony/subscriptions","organizations_url":"https://api.github.com/users/symfony/orgs","repos_url":"https://api.github.com/users/symfony/repos","events_url":"https://api.github.com/users/symfony/events{/privacy}","received_events_url":"https://api.github.com/users/symfony/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/symfony/symfony","description":"The Symfony PHP framework","fork":false,"url":"https://api.github.com/repos/symfony/symfony","forks_url":"https://api.github.com/repos/symfony/symfony/forks","keys_url":"https://api.github.com/repos/symfony/symfony/keys{/key_id}","collaborators_url":"https://api.github.com/repos/symfony/symfony/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/symfony/symfony/teams","hooks_url":"https://api.github.com/repos/symfony/symfony/hooks","issue_events_url":"https://api.github.com/repos/symfony/symfony/issues/events{/number}","events_url":"https://api.github.com/repos/symfony/symfony/events","assignees_url":"https://api.github.com/repos/symfony/symfony/assignees{/user}","branches_url":"https://api.github.com/repos/symfony/symfony/branches{/branch}","tags_url":"https://api.github.com/repos/symfony/symfony/tags","blobs_url":"https://api.github.com/repos/symfony/symfony/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/symfony/symfony/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/symfony/symfony/git/refs{/sha}","trees_url":"https://api.github.com/repos/symfony/symfony/git/trees{/sha}","statuses_url":"https://api.github.com/repos/symfony/symfony/statuses/{sha}","languages_url":"https://api.github.com/repos/symfony/symfony/languages","stargazers_url":"https://api.github.com/repos/symfony/symfony/stargazers","contributors_url":"https://api.github.com/repos/symfony/symfony/contributors","subscribers_url":"https://api.github.com/repos/symfony/symfony/subscribers","subscription_url":"https://api.github.com/repos/symfony/symfony/subscription","commits_url":"https://api.github.com/repos/symfony/symfony/commits{/sha}","git_commits_url":"https://api.github.com/repos/symfony/symfony/git/commits{/sha}","comments_url":"https://api.github.com/repos/symfony/symfony/comments{/number}","issue_comment_url":"https://api.github.com/repos/symfony/symfony/issues/comments{/number}","contents_url":"https://api.github.com/repos/symfony/symfony/contents/{+path}","compare_url":"https://api.github.com/repos/symfony/symfony/compare/{base}...{head}","merges_url":"https://api.github.com/repos/symfony/symfony/merges","archive_url":"https://api.github.com/repos/symfony/symfony/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/symfony/symfony/downloads","issues_url":"https://api.github.com/repos/symfony/symfony/issues{/number}","pulls_url":"https://api.github.com/repos/symfony/symfony/pulls{/number}","milestones_url":"https://api.github.com/repos/symfony/symfony/milestones{/number}","notifications_url":"https://api.github.com/repos/symfony/symfony/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/symfony/symfony/labels{/name}","releases_url":"https://api.github.com/repos/symfony/symfony/releases{/id}","deployments_url":"https://api.github.com/repos/symfony/symfony/deployments","created_at":"2010-01-04T14:21:21Z","updated_at":"2016-03-31T13:00:02Z","pushed_at":"2016-03-31T12:29:40Z","git_url":"git://github.com/symfony/symfony.git","ssh_url":"git@github.com:symfony/symfony.git","clone_url":"https://github.com/symfony/symfony.git","svn_url":"https://github.com/symfony/symfony","homepage":"symfony.com","size":105372,"stargazers_count":12040,"watchers_count":12040,"language":"PHP","has_issues":true,"has_downloads":false,"has_wiki":false,"has_pages":false,"forks_count":4730,"mirror_url":null,"open_issues_count":712,"forks":4730,"open_issues":712,"watchers":12040,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/symfony/symfony/pulls/18308"},"html":{"href":"https://github.com/symfony/symfony/pull/18308"},"issue":{"href":"https://api.github.com/repos/symfony/symfony/issues/18308"},"comments":{"href":"https://api.github.com/repos/symfony/symfony/issues/18308/comments"},"review_comments":{"href":"https://api.github.com/repos/symfony/symfony/pulls/18308/comments"},"review_comment":{"href":"https://api.github.com/repos/symfony/symfony/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/symfony/symfony/pulls/18308/commits"},"statuses":{"href":"https://api.github.com/repos/symfony/symfony/statuses/867ca16be3cea522ae86859a21ee3f3a2fc74068"}}}}