{"action":"created","comment":{"url":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/pulls/comments/24715260","id":24715260,"diff_hunk":"@@ -0,0 +1,67 @@\n+<?php\n+\n+/*\n+ * This file is part of the Symfony CMF package.\n+ *\n+ * (c) 2011-2014 Symfony CMF\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\\Cmf\\Bundle\\ResourceRestBundle\\Enhancer;\n+\n+use JMS\\Serializer\\Context;\n+use Puli\\Repository\\Api\\Resource\\Resource;\n+use Sonata\\AdminBundle\\Admin\\Pool;\n+use Doctrine\\Common\\Util\\ClassUtils;\n+use Symfony\\Component\\Routing\\Generator\\UrlGeneratorInterface;\n+\n+/**\n+ * Add links and metainfo from Sonata Admin\n+ *\n+ * @author Daniel Leech <daniel@dantleech.com>\n+ */\n+class SonataAdminEnhancer implements EnhancerInterface\n+{\n+    private $pool;\n+    private $urlGenerator;\n+\n+    public function __construct(Pool $pool, UrlGeneratorInterface $urlGenerator)\n+    {\n+        $this->pool = $pool;\n+        $this->urlGenerator = $urlGenerator;\n+    }\n+\n+    /**\n+     * {@inheritDoc}\n+     */\n+    public function enhance(Context $context, Resource $resource)\n+    {\n+        $object = $resource->getPayload();\n+\n+        // sonata has dependency on ClassUtils so this is fine.\n+        $class = ClassUtils::getClass($object);\n+\n+        if (false === $this->pool->hasAdminByClass($class)) {\n+            return;\n+        }\n+\n+        $admin = $this->pool->getAdminByClass($class);\n+        $visitor = $context->getVisitor();\n+\n+        $links = array();\n+        foreach (array_keys($admin->getRoutes()) as $routeName) {\n+            $url = $this->urlGenerator->generate($routeName, array(\n+                $admin->getIdParameter(),\n+                $admin->getUrlsafeIdentifier($object)\n+            ));\n+\n+            $links[$routeName] = $url;\n+        }\n+\n+        $visitor->addData('_admin_label', $admin->getLabel());\n+        $visitor->addData('_admin_links', $links);","path":"Enhancer/SonataAdminEnhancer.php","position":64,"original_position":64,"commit_id":"45c42922271aed6c9080b2b87f939d43e36e9f97","original_commit_id":"45c42922271aed6c9080b2b87f939d43e36e9f97","user":{"login":"dantleech","id":530801,"avatar_url":"https://avatars.githubusercontent.com/u/530801?v=3","gravatar_id":"","url":"https://api.github.com/users/dantleech","html_url":"https://github.com/dantleech","followers_url":"https://api.github.com/users/dantleech/followers","following_url":"https://api.github.com/users/dantleech/following{/other_user}","gists_url":"https://api.github.com/users/dantleech/gists{/gist_id}","starred_url":"https://api.github.com/users/dantleech/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dantleech/subscriptions","organizations_url":"https://api.github.com/users/dantleech/orgs","repos_url":"https://api.github.com/users/dantleech/repos","events_url":"https://api.github.com/users/dantleech/events{/privacy}","received_events_url":"https://api.github.com/users/dantleech/received_events","type":"User","site_admin":false},"body":"Should probably try using a handler and dispatching the event there.","created_at":"2015-02-14T16:23:14Z","updated_at":"2015-02-14T16:23:14Z","html_url":"https://github.com/symfony-cmf/ResourceRestBundle/pull/9#discussion_r24715260","pull_request_url":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/pulls/9","_links":{"self":{"href":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/pulls/comments/24715260"},"html":{"href":"https://github.com/symfony-cmf/ResourceRestBundle/pull/9#discussion_r24715260"},"pull_request":{"href":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/pulls/9"}}},"pull_request":{"url":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/pulls/9","id":29317975,"html_url":"https://github.com/symfony-cmf/ResourceRestBundle/pull/9","diff_url":"https://github.com/symfony-cmf/ResourceRestBundle/pull/9.diff","patch_url":"https://github.com/symfony-cmf/ResourceRestBundle/pull/9.patch","issue_url":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/issues/9","number":9,"state":"open","locked":false,"title":"SonataAdminEnhancer","user":{"login":"dantleech","id":530801,"avatar_url":"https://avatars.githubusercontent.com/u/530801?v=3","gravatar_id":"","url":"https://api.github.com/users/dantleech","html_url":"https://github.com/dantleech","followers_url":"https://api.github.com/users/dantleech/followers","following_url":"https://api.github.com/users/dantleech/following{/other_user}","gists_url":"https://api.github.com/users/dantleech/gists{/gist_id}","starred_url":"https://api.github.com/users/dantleech/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dantleech/subscriptions","organizations_url":"https://api.github.com/users/dantleech/orgs","repos_url":"https://api.github.com/users/dantleech/repos","events_url":"https://api.github.com/users/dantleech/events{/privacy}","received_events_url":"https://api.github.com/users/dantleech/received_events","type":"User","site_admin":false},"body":"This PR aims to add an \"Enhancer\" which adds meta-information from SonataAdminBundle to the Resource's REST response:\r\n\r\n- All the links\r\n- The label","created_at":"2015-02-14T08:58:06Z","updated_at":"2015-02-14T16:23:14Z","closed_at":null,"merged_at":null,"merge_commit_sha":"bb4b5bd3235eb9162eb5917e7016951e5da14ccf","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/pulls/9/commits","review_comments_url":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/pulls/9/comments","review_comment_url":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/pulls/comments/{number}","comments_url":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/issues/9/comments","statuses_url":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/statuses/45c42922271aed6c9080b2b87f939d43e36e9f97","head":{"label":"symfony-cmf:sonata_admin","ref":"sonata_admin","sha":"45c42922271aed6c9080b2b87f939d43e36e9f97","user":{"login":"symfony-cmf","id":342045,"avatar_url":"https://avatars.githubusercontent.com/u/342045?v=3","gravatar_id":"","url":"https://api.github.com/users/symfony-cmf","html_url":"https://github.com/symfony-cmf","followers_url":"https://api.github.com/users/symfony-cmf/followers","following_url":"https://api.github.com/users/symfony-cmf/following{/other_user}","gists_url":"https://api.github.com/users/symfony-cmf/gists{/gist_id}","starred_url":"https://api.github.com/users/symfony-cmf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/symfony-cmf/subscriptions","organizations_url":"https://api.github.com/users/symfony-cmf/orgs","repos_url":"https://api.github.com/users/symfony-cmf/repos","events_url":"https://api.github.com/users/symfony-cmf/events{/privacy}","received_events_url":"https://api.github.com/users/symfony-cmf/received_events","type":"Organization","site_admin":false},"repo":{"id":29090266,"name":"ResourceRestBundle","full_name":"symfony-cmf/ResourceRestBundle","owner":{"login":"symfony-cmf","id":342045,"avatar_url":"https://avatars.githubusercontent.com/u/342045?v=3","gravatar_id":"","url":"https://api.github.com/users/symfony-cmf","html_url":"https://github.com/symfony-cmf","followers_url":"https://api.github.com/users/symfony-cmf/followers","following_url":"https://api.github.com/users/symfony-cmf/following{/other_user}","gists_url":"https://api.github.com/users/symfony-cmf/gists{/gist_id}","starred_url":"https://api.github.com/users/symfony-cmf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/symfony-cmf/subscriptions","organizations_url":"https://api.github.com/users/symfony-cmf/orgs","repos_url":"https://api.github.com/users/symfony-cmf/repos","events_url":"https://api.github.com/users/symfony-cmf/events{/privacy}","received_events_url":"https://api.github.com/users/symfony-cmf/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/symfony-cmf/ResourceRestBundle","description":"REST API for Puli Resources provided through the CmfResourceBundle","fork":false,"url":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle","forks_url":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/forks","keys_url":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/keys{/key_id}","collaborators_url":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/teams","hooks_url":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/hooks","issue_events_url":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/issues/events{/number}","events_url":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/events","assignees_url":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/assignees{/user}","branches_url":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/branches{/branch}","tags_url":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/tags","blobs_url":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/git/refs{/sha}","trees_url":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/git/trees{/sha}","statuses_url":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/statuses/{sha}","languages_url":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/languages","stargazers_url":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/stargazers","contributors_url":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/contributors","subscribers_url":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/subscribers","subscription_url":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/subscription","commits_url":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/commits{/sha}","git_commits_url":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/git/commits{/sha}","comments_url":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/comments{/number}","issue_comment_url":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/issues/comments/{number}","contents_url":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/contents/{+path}","compare_url":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/compare/{base}...{head}","merges_url":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/merges","archive_url":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/downloads","issues_url":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/issues{/number}","pulls_url":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/pulls{/number}","milestones_url":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/milestones{/number}","notifications_url":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/labels{/name}","releases_url":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/releases{/id}","created_at":"2015-01-11T12:02:31Z","updated_at":"2015-02-14T07:54:01Z","pushed_at":"2015-02-14T08:56:33Z","git_url":"git://github.com/symfony-cmf/ResourceRestBundle.git","ssh_url":"git@github.com:symfony-cmf/ResourceRestBundle.git","clone_url":"https://github.com/symfony-cmf/ResourceRestBundle.git","svn_url":"https://github.com/symfony-cmf/ResourceRestBundle","homepage":"","size":332,"stargazers_count":1,"watchers_count":1,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":5,"forks":0,"open_issues":5,"watchers":1,"default_branch":"master"}},"base":{"label":"symfony-cmf:master","ref":"master","sha":"53bf3daa5cb2b9624f48a53573178dec4c46ee6a","user":{"login":"symfony-cmf","id":342045,"avatar_url":"https://avatars.githubusercontent.com/u/342045?v=3","gravatar_id":"","url":"https://api.github.com/users/symfony-cmf","html_url":"https://github.com/symfony-cmf","followers_url":"https://api.github.com/users/symfony-cmf/followers","following_url":"https://api.github.com/users/symfony-cmf/following{/other_user}","gists_url":"https://api.github.com/users/symfony-cmf/gists{/gist_id}","starred_url":"https://api.github.com/users/symfony-cmf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/symfony-cmf/subscriptions","organizations_url":"https://api.github.com/users/symfony-cmf/orgs","repos_url":"https://api.github.com/users/symfony-cmf/repos","events_url":"https://api.github.com/users/symfony-cmf/events{/privacy}","received_events_url":"https://api.github.com/users/symfony-cmf/received_events","type":"Organization","site_admin":false},"repo":{"id":29090266,"name":"ResourceRestBundle","full_name":"symfony-cmf/ResourceRestBundle","owner":{"login":"symfony-cmf","id":342045,"avatar_url":"https://avatars.githubusercontent.com/u/342045?v=3","gravatar_id":"","url":"https://api.github.com/users/symfony-cmf","html_url":"https://github.com/symfony-cmf","followers_url":"https://api.github.com/users/symfony-cmf/followers","following_url":"https://api.github.com/users/symfony-cmf/following{/other_user}","gists_url":"https://api.github.com/users/symfony-cmf/gists{/gist_id}","starred_url":"https://api.github.com/users/symfony-cmf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/symfony-cmf/subscriptions","organizations_url":"https://api.github.com/users/symfony-cmf/orgs","repos_url":"https://api.github.com/users/symfony-cmf/repos","events_url":"https://api.github.com/users/symfony-cmf/events{/privacy}","received_events_url":"https://api.github.com/users/symfony-cmf/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/symfony-cmf/ResourceRestBundle","description":"REST API for Puli Resources provided through the CmfResourceBundle","fork":false,"url":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle","forks_url":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/forks","keys_url":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/keys{/key_id}","collaborators_url":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/teams","hooks_url":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/hooks","issue_events_url":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/issues/events{/number}","events_url":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/events","assignees_url":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/assignees{/user}","branches_url":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/branches{/branch}","tags_url":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/tags","blobs_url":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/git/refs{/sha}","trees_url":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/git/trees{/sha}","statuses_url":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/statuses/{sha}","languages_url":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/languages","stargazers_url":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/stargazers","contributors_url":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/contributors","subscribers_url":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/subscribers","subscription_url":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/subscription","commits_url":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/commits{/sha}","git_commits_url":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/git/commits{/sha}","comments_url":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/comments{/number}","issue_comment_url":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/issues/comments/{number}","contents_url":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/contents/{+path}","compare_url":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/compare/{base}...{head}","merges_url":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/merges","archive_url":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/downloads","issues_url":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/issues{/number}","pulls_url":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/pulls{/number}","milestones_url":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/milestones{/number}","notifications_url":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/labels{/name}","releases_url":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/releases{/id}","created_at":"2015-01-11T12:02:31Z","updated_at":"2015-02-14T07:54:01Z","pushed_at":"2015-02-14T08:56:33Z","git_url":"git://github.com/symfony-cmf/ResourceRestBundle.git","ssh_url":"git@github.com:symfony-cmf/ResourceRestBundle.git","clone_url":"https://github.com/symfony-cmf/ResourceRestBundle.git","svn_url":"https://github.com/symfony-cmf/ResourceRestBundle","homepage":"","size":332,"stargazers_count":1,"watchers_count":1,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":5,"forks":0,"open_issues":5,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/pulls/9"},"html":{"href":"https://github.com/symfony-cmf/ResourceRestBundle/pull/9"},"issue":{"href":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/issues/9"},"comments":{"href":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/issues/9/comments"},"review_comments":{"href":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/pulls/9/comments"},"review_comment":{"href":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/pulls/9/commits"},"statuses":{"href":"https://api.github.com/repos/symfony-cmf/ResourceRestBundle/statuses/45c42922271aed6c9080b2b87f939d43e36e9f97"}}}}