{"action":"created","comment":{"url":"https://api.github.com/repos/php-cache/cache-bundle/pulls/comments/47223078","id":47223078,"diff_hunk":"@@ -0,0 +1,139 @@\n+<?php\n+\n+namespace Cache\\CacheBundle\\Routing;\n+\n+use Cache\\Taggable\\TaggablePoolInterface;\n+use Psr\\Cache\\CacheItemPoolInterface;\n+use Symfony\\Component\\EventDispatcher\\EventSubscriberInterface;\n+use Symfony\\Component\\HttpFoundation\\Request;\n+use Symfony\\Component\\HttpKernel\\Event\\GetResponseEvent;\n+use Symfony\\Component\\HttpKernel\\KernelEvents;\n+\n+/**\n+ * @author Tobias Nyholm <tobias.nyholm@gmail.com>\n+ */\n+class RouterListener\n+{\n+    /**\n+     * @var CacheItemPoolInterface\n+     */\n+    private $cache;\n+\n+    /**\n+     * @var int\n+     */\n+    private $ttl;\n+\n+    /**\n+     * @param CacheItemPoolInterface $cache\n+     * @param int                    $ttl\n+     */\n+    public function __construct(CacheItemPoolInterface $cache, $ttl)\n+    {\n+        $this->cache = $cache;\n+        $this->ttl   = $ttl;\n+    }\n+\n+    /**\n+     * Before routing, try to fetch route result from cache.\n+     *\n+     * @param GetResponseEvent $event\n+     */\n+    public function onBeforeRouting(GetResponseEvent $event)\n+    {\n+        $request = $event->getRequest();\n+\n+        if ($request->attributes->has('_controller')) {\n+            // routing is already done\n+            return;\n+        }\n+\n+        $item = $this->getCacheItem($request);\n+        if (!$item->isHit()) {\n+            return;\n+        }\n+\n+        $request->attributes->add($item->get());\n+        $request->attributes->set('_cache_hit', true);\n+    }\n+\n+    /**\n+     * After the routing, make sure to store the result in cache.\n+     *\n+     * @param GetResponseEvent $event\n+     */\n+    public function onAfterRouting(GetResponseEvent $event)\n+    {\n+        $request = $event->getRequest();\n+\n+        if (!$request->attributes->has('_controller')) {\n+            // routing has not taken place","path":"src/Routing/RouterListener.php","position":70,"original_position":70,"commit_id":"15e22acdc98b44dc87b6cc08cabadb9133556dec","original_commit_id":"15e22acdc98b44dc87b6cc08cabadb9133556dec","user":{"login":"aequasi","id":896295,"avatar_url":"https://avatars.githubusercontent.com/u/896295?v=3","gravatar_id":"","url":"https://api.github.com/users/aequasi","html_url":"https://github.com/aequasi","followers_url":"https://api.github.com/users/aequasi/followers","following_url":"https://api.github.com/users/aequasi/following{/other_user}","gists_url":"https://api.github.com/users/aequasi/gists{/gist_id}","starred_url":"https://api.github.com/users/aequasi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aequasi/subscriptions","organizations_url":"https://api.github.com/users/aequasi/orgs","repos_url":"https://api.github.com/users/aequasi/repos","events_url":"https://api.github.com/users/aequasi/events{/privacy}","received_events_url":"https://api.github.com/users/aequasi/received_events","type":"User","site_admin":false},"body":"Derp, i thought this was in onBeforeRouting for some reason.","created_at":"2015-12-10T13:04:09Z","updated_at":"2015-12-10T13:04:09Z","html_url":"https://github.com/php-cache/cache-bundle/pull/5#discussion_r47223078","pull_request_url":"https://api.github.com/repos/php-cache/cache-bundle/pulls/5","_links":{"self":{"href":"https://api.github.com/repos/php-cache/cache-bundle/pulls/comments/47223078"},"html":{"href":"https://github.com/php-cache/cache-bundle/pull/5#discussion_r47223078"},"pull_request":{"href":"https://api.github.com/repos/php-cache/cache-bundle/pulls/5"}}},"pull_request":{"url":"https://api.github.com/repos/php-cache/cache-bundle/pulls/5","id":53235511,"html_url":"https://github.com/php-cache/cache-bundle/pull/5","diff_url":"https://github.com/php-cache/cache-bundle/pull/5.diff","patch_url":"https://github.com/php-cache/cache-bundle/pull/5.patch","issue_url":"https://api.github.com/repos/php-cache/cache-bundle/issues/5","number":5,"state":"open","locked":false,"title":"Added a router listener","user":{"login":"Nyholm","id":1275206,"avatar_url":"https://avatars.githubusercontent.com/u/1275206?v=3","gravatar_id":"","url":"https://api.github.com/users/Nyholm","html_url":"https://github.com/Nyholm","followers_url":"https://api.github.com/users/Nyholm/followers","following_url":"https://api.github.com/users/Nyholm/following{/other_user}","gists_url":"https://api.github.com/users/Nyholm/gists{/gist_id}","starred_url":"https://api.github.com/users/Nyholm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Nyholm/subscriptions","organizations_url":"https://api.github.com/users/Nyholm/orgs","repos_url":"https://api.github.com/users/Nyholm/repos","events_url":"https://api.github.com/users/Nyholm/events{/privacy}","received_events_url":"https://api.github.com/users/Nyholm/received_events","type":"User","site_admin":false},"body":"This caches all the result for the router to be used for later. \r\n\r\nTODO: We need to improve the cache key.","created_at":"2015-12-10T09:47:52Z","updated_at":"2015-12-10T13:04:09Z","closed_at":null,"merged_at":null,"merge_commit_sha":"10c97fd9fb663fa1188c74025c1c8035a6feba22","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/php-cache/cache-bundle/pulls/5/commits","review_comments_url":"https://api.github.com/repos/php-cache/cache-bundle/pulls/5/comments","review_comment_url":"https://api.github.com/repos/php-cache/cache-bundle/pulls/comments{/number}","comments_url":"https://api.github.com/repos/php-cache/cache-bundle/issues/5/comments","statuses_url":"https://api.github.com/repos/php-cache/cache-bundle/statuses/15e22acdc98b44dc87b6cc08cabadb9133556dec","head":{"label":"php-cache:routing","ref":"routing","sha":"15e22acdc98b44dc87b6cc08cabadb9133556dec","user":{"login":"php-cache","id":16170857,"avatar_url":"https://avatars.githubusercontent.com/u/16170857?v=3","gravatar_id":"","url":"https://api.github.com/users/php-cache","html_url":"https://github.com/php-cache","followers_url":"https://api.github.com/users/php-cache/followers","following_url":"https://api.github.com/users/php-cache/following{/other_user}","gists_url":"https://api.github.com/users/php-cache/gists{/gist_id}","starred_url":"https://api.github.com/users/php-cache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/php-cache/subscriptions","organizations_url":"https://api.github.com/users/php-cache/orgs","repos_url":"https://api.github.com/users/php-cache/repos","events_url":"https://api.github.com/users/php-cache/events{/privacy}","received_events_url":"https://api.github.com/users/php-cache/received_events","type":"Organization","site_admin":false},"repo":{"id":47476144,"name":"cache-bundle","full_name":"php-cache/cache-bundle","owner":{"login":"php-cache","id":16170857,"avatar_url":"https://avatars.githubusercontent.com/u/16170857?v=3","gravatar_id":"","url":"https://api.github.com/users/php-cache","html_url":"https://github.com/php-cache","followers_url":"https://api.github.com/users/php-cache/followers","following_url":"https://api.github.com/users/php-cache/following{/other_user}","gists_url":"https://api.github.com/users/php-cache/gists{/gist_id}","starred_url":"https://api.github.com/users/php-cache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/php-cache/subscriptions","organizations_url":"https://api.github.com/users/php-cache/orgs","repos_url":"https://api.github.com/users/php-cache/repos","events_url":"https://api.github.com/users/php-cache/events{/privacy}","received_events_url":"https://api.github.com/users/php-cache/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/php-cache/cache-bundle","description":"Symfony PSR-6 Cache Bundle ","fork":false,"url":"https://api.github.com/repos/php-cache/cache-bundle","forks_url":"https://api.github.com/repos/php-cache/cache-bundle/forks","keys_url":"https://api.github.com/repos/php-cache/cache-bundle/keys{/key_id}","collaborators_url":"https://api.github.com/repos/php-cache/cache-bundle/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/php-cache/cache-bundle/teams","hooks_url":"https://api.github.com/repos/php-cache/cache-bundle/hooks","issue_events_url":"https://api.github.com/repos/php-cache/cache-bundle/issues/events{/number}","events_url":"https://api.github.com/repos/php-cache/cache-bundle/events","assignees_url":"https://api.github.com/repos/php-cache/cache-bundle/assignees{/user}","branches_url":"https://api.github.com/repos/php-cache/cache-bundle/branches{/branch}","tags_url":"https://api.github.com/repos/php-cache/cache-bundle/tags","blobs_url":"https://api.github.com/repos/php-cache/cache-bundle/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/php-cache/cache-bundle/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/php-cache/cache-bundle/git/refs{/sha}","trees_url":"https://api.github.com/repos/php-cache/cache-bundle/git/trees{/sha}","statuses_url":"https://api.github.com/repos/php-cache/cache-bundle/statuses/{sha}","languages_url":"https://api.github.com/repos/php-cache/cache-bundle/languages","stargazers_url":"https://api.github.com/repos/php-cache/cache-bundle/stargazers","contributors_url":"https://api.github.com/repos/php-cache/cache-bundle/contributors","subscribers_url":"https://api.github.com/repos/php-cache/cache-bundle/subscribers","subscription_url":"https://api.github.com/repos/php-cache/cache-bundle/subscription","commits_url":"https://api.github.com/repos/php-cache/cache-bundle/commits{/sha}","git_commits_url":"https://api.github.com/repos/php-cache/cache-bundle/git/commits{/sha}","comments_url":"https://api.github.com/repos/php-cache/cache-bundle/comments{/number}","issue_comment_url":"https://api.github.com/repos/php-cache/cache-bundle/issues/comments{/number}","contents_url":"https://api.github.com/repos/php-cache/cache-bundle/contents/{+path}","compare_url":"https://api.github.com/repos/php-cache/cache-bundle/compare/{base}...{head}","merges_url":"https://api.github.com/repos/php-cache/cache-bundle/merges","archive_url":"https://api.github.com/repos/php-cache/cache-bundle/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/php-cache/cache-bundle/downloads","issues_url":"https://api.github.com/repos/php-cache/cache-bundle/issues{/number}","pulls_url":"https://api.github.com/repos/php-cache/cache-bundle/pulls{/number}","milestones_url":"https://api.github.com/repos/php-cache/cache-bundle/milestones{/number}","notifications_url":"https://api.github.com/repos/php-cache/cache-bundle/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/php-cache/cache-bundle/labels{/name}","releases_url":"https://api.github.com/repos/php-cache/cache-bundle/releases{/id}","created_at":"2015-12-05T23:06:44Z","updated_at":"2015-12-05T23:50:49Z","pushed_at":"2015-12-10T10:48:37Z","git_url":"git://github.com/php-cache/cache-bundle.git","ssh_url":"git@github.com:php-cache/cache-bundle.git","clone_url":"https://github.com/php-cache/cache-bundle.git","svn_url":"https://github.com/php-cache/cache-bundle","homepage":null,"size":302,"stargazers_count":0,"watchers_count":0,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":2,"forks":2,"open_issues":2,"watchers":0,"default_branch":"master"}},"base":{"label":"php-cache:master","ref":"master","sha":"e61c73c58628d911a69c1de7563e4f74726ce7a1","user":{"login":"php-cache","id":16170857,"avatar_url":"https://avatars.githubusercontent.com/u/16170857?v=3","gravatar_id":"","url":"https://api.github.com/users/php-cache","html_url":"https://github.com/php-cache","followers_url":"https://api.github.com/users/php-cache/followers","following_url":"https://api.github.com/users/php-cache/following{/other_user}","gists_url":"https://api.github.com/users/php-cache/gists{/gist_id}","starred_url":"https://api.github.com/users/php-cache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/php-cache/subscriptions","organizations_url":"https://api.github.com/users/php-cache/orgs","repos_url":"https://api.github.com/users/php-cache/repos","events_url":"https://api.github.com/users/php-cache/events{/privacy}","received_events_url":"https://api.github.com/users/php-cache/received_events","type":"Organization","site_admin":false},"repo":{"id":47476144,"name":"cache-bundle","full_name":"php-cache/cache-bundle","owner":{"login":"php-cache","id":16170857,"avatar_url":"https://avatars.githubusercontent.com/u/16170857?v=3","gravatar_id":"","url":"https://api.github.com/users/php-cache","html_url":"https://github.com/php-cache","followers_url":"https://api.github.com/users/php-cache/followers","following_url":"https://api.github.com/users/php-cache/following{/other_user}","gists_url":"https://api.github.com/users/php-cache/gists{/gist_id}","starred_url":"https://api.github.com/users/php-cache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/php-cache/subscriptions","organizations_url":"https://api.github.com/users/php-cache/orgs","repos_url":"https://api.github.com/users/php-cache/repos","events_url":"https://api.github.com/users/php-cache/events{/privacy}","received_events_url":"https://api.github.com/users/php-cache/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/php-cache/cache-bundle","description":"Symfony PSR-6 Cache Bundle ","fork":false,"url":"https://api.github.com/repos/php-cache/cache-bundle","forks_url":"https://api.github.com/repos/php-cache/cache-bundle/forks","keys_url":"https://api.github.com/repos/php-cache/cache-bundle/keys{/key_id}","collaborators_url":"https://api.github.com/repos/php-cache/cache-bundle/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/php-cache/cache-bundle/teams","hooks_url":"https://api.github.com/repos/php-cache/cache-bundle/hooks","issue_events_url":"https://api.github.com/repos/php-cache/cache-bundle/issues/events{/number}","events_url":"https://api.github.com/repos/php-cache/cache-bundle/events","assignees_url":"https://api.github.com/repos/php-cache/cache-bundle/assignees{/user}","branches_url":"https://api.github.com/repos/php-cache/cache-bundle/branches{/branch}","tags_url":"https://api.github.com/repos/php-cache/cache-bundle/tags","blobs_url":"https://api.github.com/repos/php-cache/cache-bundle/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/php-cache/cache-bundle/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/php-cache/cache-bundle/git/refs{/sha}","trees_url":"https://api.github.com/repos/php-cache/cache-bundle/git/trees{/sha}","statuses_url":"https://api.github.com/repos/php-cache/cache-bundle/statuses/{sha}","languages_url":"https://api.github.com/repos/php-cache/cache-bundle/languages","stargazers_url":"https://api.github.com/repos/php-cache/cache-bundle/stargazers","contributors_url":"https://api.github.com/repos/php-cache/cache-bundle/contributors","subscribers_url":"https://api.github.com/repos/php-cache/cache-bundle/subscribers","subscription_url":"https://api.github.com/repos/php-cache/cache-bundle/subscription","commits_url":"https://api.github.com/repos/php-cache/cache-bundle/commits{/sha}","git_commits_url":"https://api.github.com/repos/php-cache/cache-bundle/git/commits{/sha}","comments_url":"https://api.github.com/repos/php-cache/cache-bundle/comments{/number}","issue_comment_url":"https://api.github.com/repos/php-cache/cache-bundle/issues/comments{/number}","contents_url":"https://api.github.com/repos/php-cache/cache-bundle/contents/{+path}","compare_url":"https://api.github.com/repos/php-cache/cache-bundle/compare/{base}...{head}","merges_url":"https://api.github.com/repos/php-cache/cache-bundle/merges","archive_url":"https://api.github.com/repos/php-cache/cache-bundle/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/php-cache/cache-bundle/downloads","issues_url":"https://api.github.com/repos/php-cache/cache-bundle/issues{/number}","pulls_url":"https://api.github.com/repos/php-cache/cache-bundle/pulls{/number}","milestones_url":"https://api.github.com/repos/php-cache/cache-bundle/milestones{/number}","notifications_url":"https://api.github.com/repos/php-cache/cache-bundle/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/php-cache/cache-bundle/labels{/name}","releases_url":"https://api.github.com/repos/php-cache/cache-bundle/releases{/id}","created_at":"2015-12-05T23:06:44Z","updated_at":"2015-12-05T23:50:49Z","pushed_at":"2015-12-10T10:48:37Z","git_url":"git://github.com/php-cache/cache-bundle.git","ssh_url":"git@github.com:php-cache/cache-bundle.git","clone_url":"https://github.com/php-cache/cache-bundle.git","svn_url":"https://github.com/php-cache/cache-bundle","homepage":null,"size":302,"stargazers_count":0,"watchers_count":0,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":2,"forks":2,"open_issues":2,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/php-cache/cache-bundle/pulls/5"},"html":{"href":"https://github.com/php-cache/cache-bundle/pull/5"},"issue":{"href":"https://api.github.com/repos/php-cache/cache-bundle/issues/5"},"comments":{"href":"https://api.github.com/repos/php-cache/cache-bundle/issues/5/comments"},"review_comments":{"href":"https://api.github.com/repos/php-cache/cache-bundle/pulls/5/comments"},"review_comment":{"href":"https://api.github.com/repos/php-cache/cache-bundle/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/php-cache/cache-bundle/pulls/5/commits"},"statuses":{"href":"https://api.github.com/repos/php-cache/cache-bundle/statuses/15e22acdc98b44dc87b6cc08cabadb9133556dec"}}}}