{"action":"created","comment":{"url":"https://api.github.com/repos/FriendsOfSymfony/FOSCommentBundle/pulls/comments/33473212","id":33473212,"diff_hunk":"@@ -0,0 +1,164 @@\n+<?php\n+\n+/**\n+ * This file is part of the FOSCommentBundle package.\n+ *\n+ * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>\n+ *\n+ * This source file is subject to the MIT license that is bundled\n+ * with this source code in the file LICENSE.\n+ */\n+\n+namespace FOS\\CommentBundle\\EventListener;\n+\n+use Doctrine\\Common\\Annotations\\Reader;\n+use Doctrine\\Common\\EventArgs;\n+use Doctrine\\Common\\EventSubscriber;\n+use Doctrine\\ORM\\Event\\LoadClassMetadataEventArgs;\n+use Doctrine\\ORM\\Mapping\\ClassMetadataInfo;\n+use Symfony\\Component\\DependencyInjection\\ContainerInterface;\n+\n+/**\n+ * A listener that dynamically adds relations for commentable annotation\n+ *\n+ * @author Nico Kaag <nico.kaag@genj.nl>\n+ */\n+class DynamicRelationListener implements EventSubscriber\n+{\n+    /**\n+     * @var string $threadClass contains value of 'fos_comment.model.thread.class' parameter\n+     */\n+    private $threadClass;\n+\n+    /**\n+     * @var Reader\n+     */\n+    private $reader;\n+\n+    public function __construct($threadClass, Reader $reader)\n+    {\n+        $this->threadClass = $threadClass;\n+\n+        $this->reader = $reader;\n+    }\n+\n+    /**\n+     * {@inheritDoc}\n+     */\n+    public function getSubscribedEvents()\n+    {\n+        return array(\n+            'loadClassMetadata',\n+            'postLoad',\n+        );\n+    }\n+\n+    /**\n+     * @param LoadClassMetadataEventArgs $eventArgs\n+     */\n+    public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs)\n+    {\n+        // the $metadata is the whole mapping info for this class\n+        $metadata = $eventArgs->getClassMetadata();\n+\n+        if (!$metadata->getReflectionClass()) {\n+            return;\n+        }\n+\n+        $properties = $this->getCommentableProperties($metadata->getReflectionClass());\n+\n+        if (empty($properties)) {\n+            return;\n+        }\n+\n+        $namingStrategy = $eventArgs\n+            ->getEntityManager()\n+            ->getConfiguration()\n+            ->getNamingStrategy()\n+        ;\n+\n+        foreach ($properties as $property) {\n+            $metadata->mapOneToOne(\n+                array(\n+                    'targetEntity' => $this->threadClass,\n+                    'fieldName' => $property['property'],\n+                    'cascade' => array('persist'),\n+                    'fetch' => ClassMetadataInfo::FETCH_LAZY,\n+                    'joinColumn' => array(\n+                        'name' => 'comment_thread_id',\n+                        'referencedColumnName' => 'id'\n+                    ),\n+                )\n+            );\n+        }\n+    }\n+\n+    public function postLoad(EventArgs $args)\n+    {\n+        $this->addCommentThreadToObject($args);\n+    }\n+\n+    private function addCommentThreadToObject(EventArgs $args)\n+    {\n+        $om = $args->getObjectManager();\n+        $object = $args->getObject();\n+\n+        $reflectionClass = new \\ReflectionClass($object);\n+\n+        if (!$reflectionClass) {\n+            return;\n+        }\n+        $properties = $this->getCommentableProperties($reflectionClass);\n+\n+        if (empty($properties)) {\n+            return;\n+        }\n+\n+        foreach ($properties as $property) {\n+            $commentThreadGetter = \"get\". ucfirst($property['property']);\n+            $commentThread = $object->$commentThreadGetter();\n+\n+            if (!empty($commentThread)) {\n+                return;\n+            }\n+\n+            $threadClass = $this->threadClass;\n+            $commentThread = new $threadClass();\n+\n+            $entityIdentifierMethod = \"get\" . ucfirst($property['config']->identifierProperty);\n+\n+            $commentThread->setId($object->$entityIdentifierMethod());\n+            $commentThread->setPermaLink('');\n+\n+            $commentThreadSetter = \"set\". ucfirst($property['property']);\n+            $object->$commentThreadSetter($commentThread);\n+\n+            $om->persist($object);\n+        }\n+        $om->flush();\n+    }\n+\n+    private function getCommentableProperties(\\ReflectionClass $reflectionProperties)","path":"EventListener/DynamicRelationListener.php","position":141,"original_position":141,"commit_id":"8bec734f5dea23fe9bad5a5ef106bab3f03b3e7d","original_commit_id":"8bec734f5dea23fe9bad5a5ef106bab3f03b3e7d","user":{"login":"stof","id":439401,"avatar_url":"https://avatars.githubusercontent.com/u/439401?v=3","gravatar_id":"","url":"https://api.github.com/users/stof","html_url":"https://github.com/stof","followers_url":"https://api.github.com/users/stof/followers","following_url":"https://api.github.com/users/stof/following{/other_user}","gists_url":"https://api.github.com/users/stof/gists{/gist_id}","starred_url":"https://api.github.com/users/stof/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stof/subscriptions","organizations_url":"https://api.github.com/users/stof/orgs","repos_url":"https://api.github.com/users/stof/repos","events_url":"https://api.github.com/users/stof/events{/privacy}","received_events_url":"https://api.github.com/users/stof/received_events","type":"User","site_admin":false},"body":"the variable name is weird for something holding a ReflectionClass","created_at":"2015-06-29T15:06:35Z","updated_at":"2015-06-29T15:06:35Z","html_url":"https://github.com/FriendsOfSymfony/FOSCommentBundle/pull/477#discussion_r33473212","pull_request_url":"https://api.github.com/repos/FriendsOfSymfony/FOSCommentBundle/pulls/477","_links":{"self":{"href":"https://api.github.com/repos/FriendsOfSymfony/FOSCommentBundle/pulls/comments/33473212"},"html":{"href":"https://github.com/FriendsOfSymfony/FOSCommentBundle/pull/477#discussion_r33473212"},"pull_request":{"href":"https://api.github.com/repos/FriendsOfSymfony/FOSCommentBundle/pulls/477"}}},"pull_request":{"url":"https://api.github.com/repos/FriendsOfSymfony/FOSCommentBundle/pulls/477","id":38234387,"html_url":"https://github.com/FriendsOfSymfony/FOSCommentBundle/pull/477","diff_url":"https://github.com/FriendsOfSymfony/FOSCommentBundle/pull/477.diff","patch_url":"https://github.com/FriendsOfSymfony/FOSCommentBundle/pull/477.patch","issue_url":"https://api.github.com/repos/FriendsOfSymfony/FOSCommentBundle/issues/477","number":477,"state":"open","locked":false,"title":"possibilty to attach comment threads to entities with an annotation","user":{"login":"dnagirl","id":808400,"avatar_url":"https://avatars.githubusercontent.com/u/808400?v=3","gravatar_id":"","url":"https://api.github.com/users/dnagirl","html_url":"https://github.com/dnagirl","followers_url":"https://api.github.com/users/dnagirl/followers","following_url":"https://api.github.com/users/dnagirl/following{/other_user}","gists_url":"https://api.github.com/users/dnagirl/gists{/gist_id}","starred_url":"https://api.github.com/users/dnagirl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dnagirl/subscriptions","organizations_url":"https://api.github.com/users/dnagirl/orgs","repos_url":"https://api.github.com/users/dnagirl/repos","events_url":"https://api.github.com/users/dnagirl/events{/privacy}","received_events_url":"https://api.github.com/users/dnagirl/received_events","type":"User","site_admin":false},"body":"I believe I've made the corrections to pull request  #452 that @stof  mentioned. ","created_at":"2015-06-22T14:00:55Z","updated_at":"2015-06-29T15:06:35Z","closed_at":null,"merged_at":null,"merge_commit_sha":"9575e8788bc713c0ed035ebc7fc02225b378edf3","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/FriendsOfSymfony/FOSCommentBundle/pulls/477/commits","review_comments_url":"https://api.github.com/repos/FriendsOfSymfony/FOSCommentBundle/pulls/477/comments","review_comment_url":"https://api.github.com/repos/FriendsOfSymfony/FOSCommentBundle/pulls/comments{/number}","comments_url":"https://api.github.com/repos/FriendsOfSymfony/FOSCommentBundle/issues/477/comments","statuses_url":"https://api.github.com/repos/FriendsOfSymfony/FOSCommentBundle/statuses/8bec734f5dea23fe9bad5a5ef106bab3f03b3e7d","head":{"label":"dnagirl:genj-master","ref":"genj-master","sha":"8bec734f5dea23fe9bad5a5ef106bab3f03b3e7d","user":{"login":"dnagirl","id":808400,"avatar_url":"https://avatars.githubusercontent.com/u/808400?v=3","gravatar_id":"","url":"https://api.github.com/users/dnagirl","html_url":"https://github.com/dnagirl","followers_url":"https://api.github.com/users/dnagirl/followers","following_url":"https://api.github.com/users/dnagirl/following{/other_user}","gists_url":"https://api.github.com/users/dnagirl/gists{/gist_id}","starred_url":"https://api.github.com/users/dnagirl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dnagirl/subscriptions","organizations_url":"https://api.github.com/users/dnagirl/orgs","repos_url":"https://api.github.com/users/dnagirl/repos","events_url":"https://api.github.com/users/dnagirl/events{/privacy}","received_events_url":"https://api.github.com/users/dnagirl/received_events","type":"User","site_admin":false},"repo":{"id":37533790,"name":"FOSCommentBundle","full_name":"dnagirl/FOSCommentBundle","owner":{"login":"dnagirl","id":808400,"avatar_url":"https://avatars.githubusercontent.com/u/808400?v=3","gravatar_id":"","url":"https://api.github.com/users/dnagirl","html_url":"https://github.com/dnagirl","followers_url":"https://api.github.com/users/dnagirl/followers","following_url":"https://api.github.com/users/dnagirl/following{/other_user}","gists_url":"https://api.github.com/users/dnagirl/gists{/gist_id}","starred_url":"https://api.github.com/users/dnagirl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dnagirl/subscriptions","organizations_url":"https://api.github.com/users/dnagirl/orgs","repos_url":"https://api.github.com/users/dnagirl/repos","events_url":"https://api.github.com/users/dnagirl/events{/privacy}","received_events_url":"https://api.github.com/users/dnagirl/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/dnagirl/FOSCommentBundle","description":"Threaded comments for Symfony2","fork":true,"url":"https://api.github.com/repos/dnagirl/FOSCommentBundle","forks_url":"https://api.github.com/repos/dnagirl/FOSCommentBundle/forks","keys_url":"https://api.github.com/repos/dnagirl/FOSCommentBundle/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dnagirl/FOSCommentBundle/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dnagirl/FOSCommentBundle/teams","hooks_url":"https://api.github.com/repos/dnagirl/FOSCommentBundle/hooks","issue_events_url":"https://api.github.com/repos/dnagirl/FOSCommentBundle/issues/events{/number}","events_url":"https://api.github.com/repos/dnagirl/FOSCommentBundle/events","assignees_url":"https://api.github.com/repos/dnagirl/FOSCommentBundle/assignees{/user}","branches_url":"https://api.github.com/repos/dnagirl/FOSCommentBundle/branches{/branch}","tags_url":"https://api.github.com/repos/dnagirl/FOSCommentBundle/tags","blobs_url":"https://api.github.com/repos/dnagirl/FOSCommentBundle/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dnagirl/FOSCommentBundle/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dnagirl/FOSCommentBundle/git/refs{/sha}","trees_url":"https://api.github.com/repos/dnagirl/FOSCommentBundle/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dnagirl/FOSCommentBundle/statuses/{sha}","languages_url":"https://api.github.com/repos/dnagirl/FOSCommentBundle/languages","stargazers_url":"https://api.github.com/repos/dnagirl/FOSCommentBundle/stargazers","contributors_url":"https://api.github.com/repos/dnagirl/FOSCommentBundle/contributors","subscribers_url":"https://api.github.com/repos/dnagirl/FOSCommentBundle/subscribers","subscription_url":"https://api.github.com/repos/dnagirl/FOSCommentBundle/subscription","commits_url":"https://api.github.com/repos/dnagirl/FOSCommentBundle/commits{/sha}","git_commits_url":"https://api.github.com/repos/dnagirl/FOSCommentBundle/git/commits{/sha}","comments_url":"https://api.github.com/repos/dnagirl/FOSCommentBundle/comments{/number}","issue_comment_url":"https://api.github.com/repos/dnagirl/FOSCommentBundle/issues/comments{/number}","contents_url":"https://api.github.com/repos/dnagirl/FOSCommentBundle/contents/{+path}","compare_url":"https://api.github.com/repos/dnagirl/FOSCommentBundle/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dnagirl/FOSCommentBundle/merges","archive_url":"https://api.github.com/repos/dnagirl/FOSCommentBundle/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dnagirl/FOSCommentBundle/downloads","issues_url":"https://api.github.com/repos/dnagirl/FOSCommentBundle/issues{/number}","pulls_url":"https://api.github.com/repos/dnagirl/FOSCommentBundle/pulls{/number}","milestones_url":"https://api.github.com/repos/dnagirl/FOSCommentBundle/milestones{/number}","notifications_url":"https://api.github.com/repos/dnagirl/FOSCommentBundle/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dnagirl/FOSCommentBundle/labels{/name}","releases_url":"https://api.github.com/repos/dnagirl/FOSCommentBundle/releases{/id}","created_at":"2015-06-16T14:03:58Z","updated_at":"2015-06-16T14:03:59Z","pushed_at":"2015-06-29T14:59:56Z","git_url":"git://github.com/dnagirl/FOSCommentBundle.git","ssh_url":"git@github.com:dnagirl/FOSCommentBundle.git","clone_url":"https://github.com/dnagirl/FOSCommentBundle.git","svn_url":"https://github.com/dnagirl/FOSCommentBundle","homepage":"http://friendsofsymfony.github.com/","size":1527,"stargazers_count":0,"watchers_count":0,"language":"PHP","has_issues":false,"has_downloads":true,"has_wiki":true,"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":"FriendsOfSymfony:master","ref":"master","sha":"cfe7865a027c9e1f95b7165c8e9283c49632011c","user":{"login":"FriendsOfSymfony","id":529709,"avatar_url":"https://avatars.githubusercontent.com/u/529709?v=3","gravatar_id":"","url":"https://api.github.com/users/FriendsOfSymfony","html_url":"https://github.com/FriendsOfSymfony","followers_url":"https://api.github.com/users/FriendsOfSymfony/followers","following_url":"https://api.github.com/users/FriendsOfSymfony/following{/other_user}","gists_url":"https://api.github.com/users/FriendsOfSymfony/gists{/gist_id}","starred_url":"https://api.github.com/users/FriendsOfSymfony/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/FriendsOfSymfony/subscriptions","organizations_url":"https://api.github.com/users/FriendsOfSymfony/orgs","repos_url":"https://api.github.com/users/FriendsOfSymfony/repos","events_url":"https://api.github.com/users/FriendsOfSymfony/events{/privacy}","received_events_url":"https://api.github.com/users/FriendsOfSymfony/received_events","type":"Organization","site_admin":false},"repo":{"id":1472259,"name":"FOSCommentBundle","full_name":"FriendsOfSymfony/FOSCommentBundle","owner":{"login":"FriendsOfSymfony","id":529709,"avatar_url":"https://avatars.githubusercontent.com/u/529709?v=3","gravatar_id":"","url":"https://api.github.com/users/FriendsOfSymfony","html_url":"https://github.com/FriendsOfSymfony","followers_url":"https://api.github.com/users/FriendsOfSymfony/followers","following_url":"https://api.github.com/users/FriendsOfSymfony/following{/other_user}","gists_url":"https://api.github.com/users/FriendsOfSymfony/gists{/gist_id}","starred_url":"https://api.github.com/users/FriendsOfSymfony/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/FriendsOfSymfony/subscriptions","organizations_url":"https://api.github.com/users/FriendsOfSymfony/orgs","repos_url":"https://api.github.com/users/FriendsOfSymfony/repos","events_url":"https://api.github.com/users/FriendsOfSymfony/events{/privacy}","received_events_url":"https://api.github.com/users/FriendsOfSymfony/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/FriendsOfSymfony/FOSCommentBundle","description":"Threaded comments for Symfony2","fork":false,"url":"https://api.github.com/repos/FriendsOfSymfony/FOSCommentBundle","forks_url":"https://api.github.com/repos/FriendsOfSymfony/FOSCommentBundle/forks","keys_url":"https://api.github.com/repos/FriendsOfSymfony/FOSCommentBundle/keys{/key_id}","collaborators_url":"https://api.github.com/repos/FriendsOfSymfony/FOSCommentBundle/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/FriendsOfSymfony/FOSCommentBundle/teams","hooks_url":"https://api.github.com/repos/FriendsOfSymfony/FOSCommentBundle/hooks","issue_events_url":"https://api.github.com/repos/FriendsOfSymfony/FOSCommentBundle/issues/events{/number}","events_url":"https://api.github.com/repos/FriendsOfSymfony/FOSCommentBundle/events","assignees_url":"https://api.github.com/repos/FriendsOfSymfony/FOSCommentBundle/assignees{/user}","branches_url":"https://api.github.com/repos/FriendsOfSymfony/FOSCommentBundle/branches{/branch}","tags_url":"https://api.github.com/repos/FriendsOfSymfony/FOSCommentBundle/tags","blobs_url":"https://api.github.com/repos/FriendsOfSymfony/FOSCommentBundle/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/FriendsOfSymfony/FOSCommentBundle/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/FriendsOfSymfony/FOSCommentBundle/git/refs{/sha}","trees_url":"https://api.github.com/repos/FriendsOfSymfony/FOSCommentBundle/git/trees{/sha}","statuses_url":"https://api.github.com/repos/FriendsOfSymfony/FOSCommentBundle/statuses/{sha}","languages_url":"https://api.github.com/repos/FriendsOfSymfony/FOSCommentBundle/languages","stargazers_url":"https://api.github.com/repos/FriendsOfSymfony/FOSCommentBundle/stargazers","contributors_url":"https://api.github.com/repos/FriendsOfSymfony/FOSCommentBundle/contributors","subscribers_url":"https://api.github.com/repos/FriendsOfSymfony/FOSCommentBundle/subscribers","subscription_url":"https://api.github.com/repos/FriendsOfSymfony/FOSCommentBundle/subscription","commits_url":"https://api.github.com/repos/FriendsOfSymfony/FOSCommentBundle/commits{/sha}","git_commits_url":"https://api.github.com/repos/FriendsOfSymfony/FOSCommentBundle/git/commits{/sha}","comments_url":"https://api.github.com/repos/FriendsOfSymfony/FOSCommentBundle/comments{/number}","issue_comment_url":"https://api.github.com/repos/FriendsOfSymfony/FOSCommentBundle/issues/comments{/number}","contents_url":"https://api.github.com/repos/FriendsOfSymfony/FOSCommentBundle/contents/{+path}","compare_url":"https://api.github.com/repos/FriendsOfSymfony/FOSCommentBundle/compare/{base}...{head}","merges_url":"https://api.github.com/repos/FriendsOfSymfony/FOSCommentBundle/merges","archive_url":"https://api.github.com/repos/FriendsOfSymfony/FOSCommentBundle/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/FriendsOfSymfony/FOSCommentBundle/downloads","issues_url":"https://api.github.com/repos/FriendsOfSymfony/FOSCommentBundle/issues{/number}","pulls_url":"https://api.github.com/repos/FriendsOfSymfony/FOSCommentBundle/pulls{/number}","milestones_url":"https://api.github.com/repos/FriendsOfSymfony/FOSCommentBundle/milestones{/number}","notifications_url":"https://api.github.com/repos/FriendsOfSymfony/FOSCommentBundle/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/FriendsOfSymfony/FOSCommentBundle/labels{/name}","releases_url":"https://api.github.com/repos/FriendsOfSymfony/FOSCommentBundle/releases{/id}","created_at":"2011-03-12T18:17:37Z","updated_at":"2015-06-24T20:41:55Z","pushed_at":"2015-06-29T14:59:56Z","git_url":"git://github.com/FriendsOfSymfony/FOSCommentBundle.git","ssh_url":"git@github.com:FriendsOfSymfony/FOSCommentBundle.git","clone_url":"https://github.com/FriendsOfSymfony/FOSCommentBundle.git","svn_url":"https://github.com/FriendsOfSymfony/FOSCommentBundle","homepage":"http://friendsofsymfony.github.com/","size":2540,"stargazers_count":307,"watchers_count":307,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":148,"mirror_url":null,"open_issues_count":34,"forks":148,"open_issues":34,"watchers":307,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/FriendsOfSymfony/FOSCommentBundle/pulls/477"},"html":{"href":"https://github.com/FriendsOfSymfony/FOSCommentBundle/pull/477"},"issue":{"href":"https://api.github.com/repos/FriendsOfSymfony/FOSCommentBundle/issues/477"},"comments":{"href":"https://api.github.com/repos/FriendsOfSymfony/FOSCommentBundle/issues/477/comments"},"review_comments":{"href":"https://api.github.com/repos/FriendsOfSymfony/FOSCommentBundle/pulls/477/comments"},"review_comment":{"href":"https://api.github.com/repos/FriendsOfSymfony/FOSCommentBundle/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/FriendsOfSymfony/FOSCommentBundle/pulls/477/commits"},"statuses":{"href":"https://api.github.com/repos/FriendsOfSymfony/FOSCommentBundle/statuses/8bec734f5dea23fe9bad5a5ef106bab3f03b3e7d"}}}}