{"action":"created","comment":{"url":"https://api.github.com/repos/massiveart/MassiveSearchBundle/pulls/comments/23674284","id":23674284,"diff_hunk":"@@ -0,0 +1,216 @@\n+<?php\n+/*\n+ * This file is part of the Sulu CMS.\n+ *\n+ * (c) MASSIVE ART WebServices GmbH\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 Massive\\Bundle\\SearchBundle\\Search;\n+\n+use Symfony\\Component\\ExpressionLanguage\\ExpressionLanguage;\n+use Massive\\Bundle\\SearchBundle\\Search\\Metadata\\IndexMetadata;\n+use Symfony\\Component\\PropertyAccess\\PropertyAccess;\n+use Massive\\Bundle\\SearchBundle\\Search\\Factory;\n+\n+/**\n+ * Convert mapped objects to search documents\n+ */\n+class ObjectToDocumentConverter\n+{\n+    /**\n+     * @var ExpressionLanguage\n+     */\n+    private $expressionLanguage;\n+\n+    /**\n+     * @var PropertyAccess\n+     */\n+    private $accesor;\n+\n+    /**\n+     * @var Factory\n+     */\n+    private $factory;\n+\n+    public function __construct(Factory $factory, ExpressionLanguage $expressionLanguage)\n+    {\n+        $this->expressionLanguage = $expressionLanguage;\n+        $this->factory = $factory;\n+        $this->accessor = PropertyAccess::createPropertyAccessor();\n+    }\n+\n+    /**\n+     * Map the given object to a new document using the\n+     * given metadata.\n+     *\n+     * @param IndexMetadata $metadata\n+     * @param object $object\n+     * @return Document\n+     */\n+    public function objectToDocument(IndexMetadata $metadata, $object)\n+    {\n+        $idField = $metadata->getIdField();\n+        $urlField = $metadata->getUrlField();\n+        $titleField = $metadata->getTitleField();\n+        $descriptionField = $metadata->getDescriptionField();\n+        $imageUrlField = $metadata->getImageUrlField();\n+        $localeField = $metadata->getLocaleField();\n+        $fieldMapping = $metadata->getFieldMapping();\n+\n+        $document = $this->factory->makeDocument();\n+        $document->setId($this->getValue($object, $idField));\n+        $document->setClass($metadata->getName());\n+\n+        if ($urlField) {\n+            $url = $this->getValue($object, $urlField);\n+            if ($url) {\n+                $document->setUrl($url);\n+            }\n+        }\n+\n+        if ($titleField) {\n+            $title = $this->getValue($object, $titleField);\n+            if ($title) {\n+                $document->setTitle($title);\n+            }\n+        }\n+\n+        if ($descriptionField) {\n+            $description = $this->getValue($object, $descriptionField);\n+            if ($description) {\n+                $document->setDescription($description);\n+            }\n+        }\n+\n+        if ($imageUrlField) {\n+            $imageUrl = $this->getValue($object, $imageUrlField);\n+            $document->setImageUrl($imageUrl);\n+        }\n+\n+        if ($localeField) {\n+            $locale = $this->getValue($object, $localeField);\n+            $document->setLocale($locale);\n+        }\n+\n+        $this->populateDocument($document, $object, $fieldMapping);\n+\n+        return $document;\n+    }\n+\n+    /**\n+     * Evaluate the value from the given object and field\n+     *\n+     * @param mixed $object\n+     * @param mixed $field\n+     */\n+    private function getValue($object, $field)\n+    {\n+        switch (get_class($field)) {\n+            case 'Massive\\Bundle\\SearchBundle\\Search\\Metadata\\Property':\n+                return $this->getPropertyValue($object, $field);\n+            case 'Massive\\Bundle\\SearchBundle\\Search\\Metadata\\Expression':\n+                return $this->getExpressionValue($object, $field);\n+\n+        }\n+\n+        throw new \\RuntimeException(sprintf(\n+            'Expected either a Property or an Expression when converting object of class \"%s\" to document',\n+            get_class($object)\n+        ));\n+    }\n+\n+    /**\n+     * Evaluate a property (using PropertyAccess)\n+     *\n+     * @param mixed $object\n+     * @param mixed $field\n+     */\n+    private function getPropertyValue($object, $field)\n+    {\n+        return $this->accessor->getValue($object, $field->getProperty());\n+    }\n+\n+    /**\n+     * Evaluate an expression (ExpressionLanguage)\n+     *\n+     * @param mixed $object\n+     * @param mixed $field\n+     */\n+    private function getExpressionValue($object, $field)","path":"Search/ObjectToDocumentConverter.php","position":142,"original_position":142,"commit_id":"2a95ca35b546d1415b14841d79c770a707dc3881","original_commit_id":"2a95ca35b546d1415b14841d79c770a707dc3881","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":"type hint ","created_at":"2015-01-28T09:25:41Z","updated_at":"2015-01-28T09:25:41Z","html_url":"https://github.com/massiveart/MassiveSearchBundle/pull/18#discussion_r23674284","pull_request_url":"https://api.github.com/repos/massiveart/MassiveSearchBundle/pulls/18","_links":{"self":{"href":"https://api.github.com/repos/massiveart/MassiveSearchBundle/pulls/comments/23674284"},"html":{"href":"https://github.com/massiveart/MassiveSearchBundle/pull/18#discussion_r23674284"},"pull_request":{"href":"https://api.github.com/repos/massiveart/MassiveSearchBundle/pulls/18"}}},"pull_request":{"url":"https://api.github.com/repos/massiveart/MassiveSearchBundle/pulls/18","id":28102164,"html_url":"https://github.com/massiveart/MassiveSearchBundle/pull/18","diff_url":"https://github.com/massiveart/MassiveSearchBundle/pull/18.diff","patch_url":"https://github.com/massiveart/MassiveSearchBundle/pull/18.patch","issue_url":"https://api.github.com/repos/massiveart/MassiveSearchBundle/issues/18","number":18,"state":"open","locked":false,"title":"Feature/rest api","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 adds a Doctrine ORM subscriber and a REST API.\r\n\r\n- The Doctrine ORM subscriber will automatically index/deindex mapped ORM documents.\r\n- The REST API provides a simple controller to perform a search query using parameters `query`, `index` and `locale` and receieve a JSON response.\r\n\r\nTodo\r\n\r\n- [ ] Documentation\r\n- [ ] API to retrieve valid indexes (or maybe that should be defined elsewhere?)\r\n- [ ] ORM subscriber DI Configuration + tag","created_at":"2015-01-27T11:44:40Z","updated_at":"2015-01-28T09:25:41Z","closed_at":null,"merged_at":null,"merge_commit_sha":"425f7c1f5b76f45a9e6861b8eee3fcc0a3404ef9","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/massiveart/MassiveSearchBundle/pulls/18/commits","review_comments_url":"https://api.github.com/repos/massiveart/MassiveSearchBundle/pulls/18/comments","review_comment_url":"https://api.github.com/repos/massiveart/MassiveSearchBundle/pulls/comments/{number}","comments_url":"https://api.github.com/repos/massiveart/MassiveSearchBundle/issues/18/comments","statuses_url":"https://api.github.com/repos/massiveart/MassiveSearchBundle/statuses/2a95ca35b546d1415b14841d79c770a707dc3881","head":{"label":"massiveart:feature/rest-api","ref":"feature/rest-api","sha":"2a95ca35b546d1415b14841d79c770a707dc3881","user":{"login":"massiveart","id":854731,"avatar_url":"https://avatars.githubusercontent.com/u/854731?v=3","gravatar_id":"","url":"https://api.github.com/users/massiveart","html_url":"https://github.com/massiveart","followers_url":"https://api.github.com/users/massiveart/followers","following_url":"https://api.github.com/users/massiveart/following{/other_user}","gists_url":"https://api.github.com/users/massiveart/gists{/gist_id}","starred_url":"https://api.github.com/users/massiveart/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/massiveart/subscriptions","organizations_url":"https://api.github.com/users/massiveart/orgs","repos_url":"https://api.github.com/users/massiveart/repos","events_url":"https://api.github.com/users/massiveart/events{/privacy}","received_events_url":"https://api.github.com/users/massiveart/received_events","type":"Organization","site_admin":false},"repo":{"id":23216604,"name":"MassiveSearchBundle","full_name":"massiveart/MassiveSearchBundle","owner":{"login":"massiveart","id":854731,"avatar_url":"https://avatars.githubusercontent.com/u/854731?v=3","gravatar_id":"","url":"https://api.github.com/users/massiveart","html_url":"https://github.com/massiveart","followers_url":"https://api.github.com/users/massiveart/followers","following_url":"https://api.github.com/users/massiveart/following{/other_user}","gists_url":"https://api.github.com/users/massiveart/gists{/gist_id}","starred_url":"https://api.github.com/users/massiveart/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/massiveart/subscriptions","organizations_url":"https://api.github.com/users/massiveart/orgs","repos_url":"https://api.github.com/users/massiveart/repos","events_url":"https://api.github.com/users/massiveart/events{/privacy}","received_events_url":"https://api.github.com/users/massiveart/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/massiveart/MassiveSearchBundle","description":"","fork":false,"url":"https://api.github.com/repos/massiveart/MassiveSearchBundle","forks_url":"https://api.github.com/repos/massiveart/MassiveSearchBundle/forks","keys_url":"https://api.github.com/repos/massiveart/MassiveSearchBundle/keys{/key_id}","collaborators_url":"https://api.github.com/repos/massiveart/MassiveSearchBundle/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/massiveart/MassiveSearchBundle/teams","hooks_url":"https://api.github.com/repos/massiveart/MassiveSearchBundle/hooks","issue_events_url":"https://api.github.com/repos/massiveart/MassiveSearchBundle/issues/events{/number}","events_url":"https://api.github.com/repos/massiveart/MassiveSearchBundle/events","assignees_url":"https://api.github.com/repos/massiveart/MassiveSearchBundle/assignees{/user}","branches_url":"https://api.github.com/repos/massiveart/MassiveSearchBundle/branches{/branch}","tags_url":"https://api.github.com/repos/massiveart/MassiveSearchBundle/tags","blobs_url":"https://api.github.com/repos/massiveart/MassiveSearchBundle/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/massiveart/MassiveSearchBundle/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/massiveart/MassiveSearchBundle/git/refs{/sha}","trees_url":"https://api.github.com/repos/massiveart/MassiveSearchBundle/git/trees{/sha}","statuses_url":"https://api.github.com/repos/massiveart/MassiveSearchBundle/statuses/{sha}","languages_url":"https://api.github.com/repos/massiveart/MassiveSearchBundle/languages","stargazers_url":"https://api.github.com/repos/massiveart/MassiveSearchBundle/stargazers","contributors_url":"https://api.github.com/repos/massiveart/MassiveSearchBundle/contributors","subscribers_url":"https://api.github.com/repos/massiveart/MassiveSearchBundle/subscribers","subscription_url":"https://api.github.com/repos/massiveart/MassiveSearchBundle/subscription","commits_url":"https://api.github.com/repos/massiveart/MassiveSearchBundle/commits{/sha}","git_commits_url":"https://api.github.com/repos/massiveart/MassiveSearchBundle/git/commits{/sha}","comments_url":"https://api.github.com/repos/massiveart/MassiveSearchBundle/comments{/number}","issue_comment_url":"https://api.github.com/repos/massiveart/MassiveSearchBundle/issues/comments/{number}","contents_url":"https://api.github.com/repos/massiveart/MassiveSearchBundle/contents/{+path}","compare_url":"https://api.github.com/repos/massiveart/MassiveSearchBundle/compare/{base}...{head}","merges_url":"https://api.github.com/repos/massiveart/MassiveSearchBundle/merges","archive_url":"https://api.github.com/repos/massiveart/MassiveSearchBundle/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/massiveart/MassiveSearchBundle/downloads","issues_url":"https://api.github.com/repos/massiveart/MassiveSearchBundle/issues{/number}","pulls_url":"https://api.github.com/repos/massiveart/MassiveSearchBundle/pulls{/number}","milestones_url":"https://api.github.com/repos/massiveart/MassiveSearchBundle/milestones{/number}","notifications_url":"https://api.github.com/repos/massiveart/MassiveSearchBundle/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/massiveart/MassiveSearchBundle/labels{/name}","releases_url":"https://api.github.com/repos/massiveart/MassiveSearchBundle/releases{/id}","created_at":"2014-08-22T07:19:25Z","updated_at":"2015-01-23T12:40:44Z","pushed_at":"2015-01-28T09:23:21Z","git_url":"git://github.com/massiveart/MassiveSearchBundle.git","ssh_url":"git@github.com:massiveart/MassiveSearchBundle.git","clone_url":"https://github.com/massiveart/MassiveSearchBundle.git","svn_url":"https://github.com/massiveart/MassiveSearchBundle","homepage":null,"size":1140,"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":7,"forks":0,"open_issues":7,"watchers":1,"default_branch":"develop"}},"base":{"label":"massiveart:develop","ref":"develop","sha":"21870aa6155d5a0fbb50d770bb671c21b6943846","user":{"login":"massiveart","id":854731,"avatar_url":"https://avatars.githubusercontent.com/u/854731?v=3","gravatar_id":"","url":"https://api.github.com/users/massiveart","html_url":"https://github.com/massiveart","followers_url":"https://api.github.com/users/massiveart/followers","following_url":"https://api.github.com/users/massiveart/following{/other_user}","gists_url":"https://api.github.com/users/massiveart/gists{/gist_id}","starred_url":"https://api.github.com/users/massiveart/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/massiveart/subscriptions","organizations_url":"https://api.github.com/users/massiveart/orgs","repos_url":"https://api.github.com/users/massiveart/repos","events_url":"https://api.github.com/users/massiveart/events{/privacy}","received_events_url":"https://api.github.com/users/massiveart/received_events","type":"Organization","site_admin":false},"repo":{"id":23216604,"name":"MassiveSearchBundle","full_name":"massiveart/MassiveSearchBundle","owner":{"login":"massiveart","id":854731,"avatar_url":"https://avatars.githubusercontent.com/u/854731?v=3","gravatar_id":"","url":"https://api.github.com/users/massiveart","html_url":"https://github.com/massiveart","followers_url":"https://api.github.com/users/massiveart/followers","following_url":"https://api.github.com/users/massiveart/following{/other_user}","gists_url":"https://api.github.com/users/massiveart/gists{/gist_id}","starred_url":"https://api.github.com/users/massiveart/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/massiveart/subscriptions","organizations_url":"https://api.github.com/users/massiveart/orgs","repos_url":"https://api.github.com/users/massiveart/repos","events_url":"https://api.github.com/users/massiveart/events{/privacy}","received_events_url":"https://api.github.com/users/massiveart/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/massiveart/MassiveSearchBundle","description":"","fork":false,"url":"https://api.github.com/repos/massiveart/MassiveSearchBundle","forks_url":"https://api.github.com/repos/massiveart/MassiveSearchBundle/forks","keys_url":"https://api.github.com/repos/massiveart/MassiveSearchBundle/keys{/key_id}","collaborators_url":"https://api.github.com/repos/massiveart/MassiveSearchBundle/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/massiveart/MassiveSearchBundle/teams","hooks_url":"https://api.github.com/repos/massiveart/MassiveSearchBundle/hooks","issue_events_url":"https://api.github.com/repos/massiveart/MassiveSearchBundle/issues/events{/number}","events_url":"https://api.github.com/repos/massiveart/MassiveSearchBundle/events","assignees_url":"https://api.github.com/repos/massiveart/MassiveSearchBundle/assignees{/user}","branches_url":"https://api.github.com/repos/massiveart/MassiveSearchBundle/branches{/branch}","tags_url":"https://api.github.com/repos/massiveart/MassiveSearchBundle/tags","blobs_url":"https://api.github.com/repos/massiveart/MassiveSearchBundle/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/massiveart/MassiveSearchBundle/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/massiveart/MassiveSearchBundle/git/refs{/sha}","trees_url":"https://api.github.com/repos/massiveart/MassiveSearchBundle/git/trees{/sha}","statuses_url":"https://api.github.com/repos/massiveart/MassiveSearchBundle/statuses/{sha}","languages_url":"https://api.github.com/repos/massiveart/MassiveSearchBundle/languages","stargazers_url":"https://api.github.com/repos/massiveart/MassiveSearchBundle/stargazers","contributors_url":"https://api.github.com/repos/massiveart/MassiveSearchBundle/contributors","subscribers_url":"https://api.github.com/repos/massiveart/MassiveSearchBundle/subscribers","subscription_url":"https://api.github.com/repos/massiveart/MassiveSearchBundle/subscription","commits_url":"https://api.github.com/repos/massiveart/MassiveSearchBundle/commits{/sha}","git_commits_url":"https://api.github.com/repos/massiveart/MassiveSearchBundle/git/commits{/sha}","comments_url":"https://api.github.com/repos/massiveart/MassiveSearchBundle/comments{/number}","issue_comment_url":"https://api.github.com/repos/massiveart/MassiveSearchBundle/issues/comments/{number}","contents_url":"https://api.github.com/repos/massiveart/MassiveSearchBundle/contents/{+path}","compare_url":"https://api.github.com/repos/massiveart/MassiveSearchBundle/compare/{base}...{head}","merges_url":"https://api.github.com/repos/massiveart/MassiveSearchBundle/merges","archive_url":"https://api.github.com/repos/massiveart/MassiveSearchBundle/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/massiveart/MassiveSearchBundle/downloads","issues_url":"https://api.github.com/repos/massiveart/MassiveSearchBundle/issues{/number}","pulls_url":"https://api.github.com/repos/massiveart/MassiveSearchBundle/pulls{/number}","milestones_url":"https://api.github.com/repos/massiveart/MassiveSearchBundle/milestones{/number}","notifications_url":"https://api.github.com/repos/massiveart/MassiveSearchBundle/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/massiveart/MassiveSearchBundle/labels{/name}","releases_url":"https://api.github.com/repos/massiveart/MassiveSearchBundle/releases{/id}","created_at":"2014-08-22T07:19:25Z","updated_at":"2015-01-23T12:40:44Z","pushed_at":"2015-01-28T09:23:21Z","git_url":"git://github.com/massiveart/MassiveSearchBundle.git","ssh_url":"git@github.com:massiveart/MassiveSearchBundle.git","clone_url":"https://github.com/massiveart/MassiveSearchBundle.git","svn_url":"https://github.com/massiveart/MassiveSearchBundle","homepage":null,"size":1140,"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":7,"forks":0,"open_issues":7,"watchers":1,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/massiveart/MassiveSearchBundle/pulls/18"},"html":{"href":"https://github.com/massiveart/MassiveSearchBundle/pull/18"},"issue":{"href":"https://api.github.com/repos/massiveart/MassiveSearchBundle/issues/18"},"comments":{"href":"https://api.github.com/repos/massiveart/MassiveSearchBundle/issues/18/comments"},"review_comments":{"href":"https://api.github.com/repos/massiveart/MassiveSearchBundle/pulls/18/comments"},"review_comment":{"href":"https://api.github.com/repos/massiveart/MassiveSearchBundle/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/massiveart/MassiveSearchBundle/pulls/18/commits"},"statuses":{"href":"https://api.github.com/repos/massiveart/MassiveSearchBundle/statuses/2a95ca35b546d1415b14841d79c770a707dc3881"}}}}