{"action":"created","comment":{"url":"https://api.github.com/repos/bravo3/orm/pulls/comments/46109866","id":46109866,"diff_hunk":"@@ -0,0 +1,332 @@\n+<?php\n+namespace Bravo3\\Orm\\Mappers\\Yaml;\n+\n+use Bravo3\\Orm\\Mappers\\Metadata\\Entity;\n+use Bravo3\\Orm\\Mappers\\Metadata\\Sortable;\n+use Bravo3\\Orm\\Mappers\\Portation\\AbstractMapWriter;\n+use Doctrine\\Common\\Inflector\\Inflector;\n+use Symfony\\Component\\Yaml\\Yaml;\n+\n+class YamlMapWriter extends AbstractMapWriter\n+{\n+    /**\n+     * @var string\n+     */\n+    protected $output_fn;\n+\n+    /**\n+     * @var array\n+     */\n+    protected $main_buffer = [];\n+\n+    /**\n+     * @var array\n+     */\n+    protected $sub_buffers = [];\n+\n+    /**\n+     * @var int\n+     */\n+    protected $inline_level = 3;\n+\n+    /**\n+     * @var int\n+     */\n+    protected $indent_spaces = 4;\n+\n+    /**\n+     * @param string $output Primary output file\n+     */\n+    public function __construct($output = null)\n+    {\n+        $this->output_fn = $output;\n+    }\n+\n+    /**\n+     * Write metadata for a given entity, using the input EntityManager that must be preset\n+     *\n+     * @param object      $entity   Entity with existing mapping data\n+     * @param string|null $resource File name to write data, if null a default or common value will be used\n+     * @return void\n+     */\n+    public function compileMetadataForEntity($entity, $resource = null)\n+    {\n+        $this->managerMustExist();\n+\n+        $md = $this->manager->getMapper()->getEntityMetadata($entity);\n+\n+        $data = [\n+            Schema::TABLE_NAME => $md->getTableName(),\n+            Schema::COLUMNS    => $this->compileColumns($md),\n+        ];\n+\n+        if ($sortables = $this->compileSortIndices($md)) {\n+            $data[Schema::SORT_INDICES] = $sortables;\n+        }\n+\n+        if ($indices = $this->compileStdIndices($md)) {\n+            $data[Schema::STD_INDICES] = $indices;\n+        }\n+\n+        if ($resource) {\n+            $this->sub_buffers[$resource] = [$md->getClassName() => $data];\n+        } else {\n+            $this->main_buffer[$md->getClassName()] = $data;\n+        }\n+    }\n+\n+    /**\n+     * Compile normal indices\n+     *\n+     * @param Entity $md\n+     * @return array\n+     */\n+    private function compileStdIndices(Entity $md)\n+    {\n+        $out     = [];\n+        $indices = $md->getIndices();\n+\n+        foreach ($indices as $index) {\n+            $data = [];\n+\n+            if ($index->getColumns()) {\n+                $data[Schema::INDEX_COLUMNS] = $index->getColumns();\n+            }\n+\n+            if ($index->getMethods()) {\n+                $data[Schema::INDEX_METHODS] = $index->getMethods();\n+            }\n+\n+            $out[$index->getName()] = $data;\n+        }\n+\n+        return $out;\n+    }\n+\n+    /**\n+     * Compile all sortable table indices\n+     *\n+     * @param Entity $md\n+     * @return array\n+     */\n+    private function compileSortIndices(Entity $md)\n+    {\n+        return $this->compileSortables($md->getSortables());\n+    }\n+\n+    /**\n+     * Compile sortables into an array\n+     *\n+     * @param Sortable[] $sortables\n+     * @return array\n+     */\n+    private function compileSortables(array $sortables)\n+    {\n+        $out = [];\n+\n+        foreach ($sortables as $index) {\n+            $data = [];\n+\n+            if ($index->getColumn()) {\n+                $data[Schema::INDEX_COLUMN] = $index->getColumn();\n+            }\n+\n+            $conditions = $this->compileConditions($index->getConditions());\n+            if ($conditions) {\n+                $data[Schema::INDEX_CONDITIONS] = $conditions;\n+            }\n+\n+            $out[$index->getName()] = $data;\n+        }\n+\n+        return $out;\n+    }\n+\n+    /**\n+     * Compile conditions into an array\n+     *\n+     * @param \\Bravo3\\Orm\\Mappers\\Metadata\\Condition[] $conditions\n+     * @return array\n+     */\n+    private function compileConditions(array $conditions)\n+    {\n+        $out = [];\n+\n+        foreach ($conditions as $condition) {\n+            $data = [Schema::CONDITION_VALUE => $condition->getValue()];\n+\n+            if ($condition->getColumn()) {\n+                $data[Schema::CONDITION_COLUMN] = $condition->getColumn();\n+            }\n+\n+            if ($condition->getMethod()) {\n+                $data[Schema::CONDITION_METHOD] = $condition->getMethod();\n+            }\n+\n+            if ($condition->getComparison() && ($condition->getComparison() != '=')) {\n+                $data[Schema::CONDITION_COMPARISON] = $condition->getComparison();\n+            }\n+\n+            $out[] = $data;\n+        }\n+\n+        return $out;\n+    }\n+\n+    /**\n+     * Compiles all columns for an entity\n+     *\n+     * @param Entity $md\n+     * @return array\n+     */\n+    private function compileColumns(Entity $md)\n+    {\n+        $out     = [];\n+        $columns = $md->getColumns();\n+\n+        foreach ($columns as $column) {\n+            $data = [\n+                Schema::COLUMN_TYPE => $column->getType()->value(),\n+            ];\n+\n+            if ($column->isId()) {\n+                $data[Schema::COLUMN_ID] = true;\n+            }\n+\n+            $default_getter = 'get'.Inflector::classify($column->getProperty());","path":"src/Bravo3/Orm/Mappers/Yaml/YamlMapWriter.php","position":196,"original_position":196,"commit_id":"c96da7f738c892b4b4df7390e8e12943176d8534","original_commit_id":"c96da7f738c892b4b4df7390e8e12943176d8534","user":{"login":"purinda","id":3181510,"avatar_url":"https://avatars.githubusercontent.com/u/3181510?v=3","gravatar_id":"","url":"https://api.github.com/users/purinda","html_url":"https://github.com/purinda","followers_url":"https://api.github.com/users/purinda/followers","following_url":"https://api.github.com/users/purinda/following{/other_user}","gists_url":"https://api.github.com/users/purinda/gists{/gist_id}","starred_url":"https://api.github.com/users/purinda/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/purinda/subscriptions","organizations_url":"https://api.github.com/users/purinda/orgs","repos_url":"https://api.github.com/users/purinda/repos","events_url":"https://api.github.com/users/purinda/events{/privacy}","received_events_url":"https://api.github.com/users/purinda/received_events","type":"User","site_admin":false},"body":"`symfony.com/doc/current/components/property_access/introduction.html` ?","created_at":"2015-11-30T05:33:26Z","updated_at":"2015-11-30T05:33:26Z","html_url":"https://github.com/bravo3/orm/pull/37#discussion_r46109866","pull_request_url":"https://api.github.com/repos/bravo3/orm/pulls/37","_links":{"self":{"href":"https://api.github.com/repos/bravo3/orm/pulls/comments/46109866"},"html":{"href":"https://github.com/bravo3/orm/pull/37#discussion_r46109866"},"pull_request":{"href":"https://api.github.com/repos/bravo3/orm/pulls/37"}}},"pull_request":{"url":"https://api.github.com/repos/bravo3/orm/pulls/37","id":52080343,"html_url":"https://github.com/bravo3/orm/pull/37","diff_url":"https://github.com/bravo3/orm/pull/37.diff","patch_url":"https://github.com/bravo3/orm/pull/37.patch","issue_url":"https://api.github.com/repos/bravo3/orm/issues/37","number":37,"state":"open","locked":false,"title":"YAML mappings","user":{"login":"jordonsc","id":347611,"avatar_url":"https://avatars.githubusercontent.com/u/347611?v=3","gravatar_id":"","url":"https://api.github.com/users/jordonsc","html_url":"https://github.com/jordonsc","followers_url":"https://api.github.com/users/jordonsc/followers","following_url":"https://api.github.com/users/jordonsc/following{/other_user}","gists_url":"https://api.github.com/users/jordonsc/gists{/gist_id}","starred_url":"https://api.github.com/users/jordonsc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jordonsc/subscriptions","organizations_url":"https://api.github.com/users/jordonsc/orgs","repos_url":"https://api.github.com/users/jordonsc/repos","events_url":"https://api.github.com/users/jordonsc/events{/privacy}","received_events_url":"https://api.github.com/users/jordonsc/received_events","type":"User","site_admin":false},"body":"* Added YAML mapper\r\n* Added map portation\r\n* Added an entity locator for export and portation uses\r\n* Solves issue #36 ","created_at":"2015-11-30T02:46:52Z","updated_at":"2015-11-30T05:33:26Z","closed_at":null,"merged_at":null,"merge_commit_sha":"32e05f0a0195c18c728dc420581bd8862137f891","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/bravo3/orm/pulls/37/commits","review_comments_url":"https://api.github.com/repos/bravo3/orm/pulls/37/comments","review_comment_url":"https://api.github.com/repos/bravo3/orm/pulls/comments{/number}","comments_url":"https://api.github.com/repos/bravo3/orm/issues/37/comments","statuses_url":"https://api.github.com/repos/bravo3/orm/statuses/c96da7f738c892b4b4df7390e8e12943176d8534","head":{"label":"bravo3:feature/yaml-mapper","ref":"feature/yaml-mapper","sha":"c96da7f738c892b4b4df7390e8e12943176d8534","user":{"login":"bravo3","id":7390697,"avatar_url":"https://avatars.githubusercontent.com/u/7390697?v=3","gravatar_id":"","url":"https://api.github.com/users/bravo3","html_url":"https://github.com/bravo3","followers_url":"https://api.github.com/users/bravo3/followers","following_url":"https://api.github.com/users/bravo3/following{/other_user}","gists_url":"https://api.github.com/users/bravo3/gists{/gist_id}","starred_url":"https://api.github.com/users/bravo3/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bravo3/subscriptions","organizations_url":"https://api.github.com/users/bravo3/orgs","repos_url":"https://api.github.com/users/bravo3/repos","events_url":"https://api.github.com/users/bravo3/events{/privacy}","received_events_url":"https://api.github.com/users/bravo3/received_events","type":"Organization","site_admin":false},"repo":{"id":28211142,"name":"orm","full_name":"bravo3/orm","owner":{"login":"bravo3","id":7390697,"avatar_url":"https://avatars.githubusercontent.com/u/7390697?v=3","gravatar_id":"","url":"https://api.github.com/users/bravo3","html_url":"https://github.com/bravo3","followers_url":"https://api.github.com/users/bravo3/followers","following_url":"https://api.github.com/users/bravo3/following{/other_user}","gists_url":"https://api.github.com/users/bravo3/gists{/gist_id}","starred_url":"https://api.github.com/users/bravo3/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bravo3/subscriptions","organizations_url":"https://api.github.com/users/bravo3/orgs","repos_url":"https://api.github.com/users/bravo3/repos","events_url":"https://api.github.com/users/bravo3/events{/privacy}","received_events_url":"https://api.github.com/users/bravo3/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/bravo3/orm","description":"Document ORM for NoSQL databases like Redis","fork":false,"url":"https://api.github.com/repos/bravo3/orm","forks_url":"https://api.github.com/repos/bravo3/orm/forks","keys_url":"https://api.github.com/repos/bravo3/orm/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bravo3/orm/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bravo3/orm/teams","hooks_url":"https://api.github.com/repos/bravo3/orm/hooks","issue_events_url":"https://api.github.com/repos/bravo3/orm/issues/events{/number}","events_url":"https://api.github.com/repos/bravo3/orm/events","assignees_url":"https://api.github.com/repos/bravo3/orm/assignees{/user}","branches_url":"https://api.github.com/repos/bravo3/orm/branches{/branch}","tags_url":"https://api.github.com/repos/bravo3/orm/tags","blobs_url":"https://api.github.com/repos/bravo3/orm/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bravo3/orm/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bravo3/orm/git/refs{/sha}","trees_url":"https://api.github.com/repos/bravo3/orm/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bravo3/orm/statuses/{sha}","languages_url":"https://api.github.com/repos/bravo3/orm/languages","stargazers_url":"https://api.github.com/repos/bravo3/orm/stargazers","contributors_url":"https://api.github.com/repos/bravo3/orm/contributors","subscribers_url":"https://api.github.com/repos/bravo3/orm/subscribers","subscription_url":"https://api.github.com/repos/bravo3/orm/subscription","commits_url":"https://api.github.com/repos/bravo3/orm/commits{/sha}","git_commits_url":"https://api.github.com/repos/bravo3/orm/git/commits{/sha}","comments_url":"https://api.github.com/repos/bravo3/orm/comments{/number}","issue_comment_url":"https://api.github.com/repos/bravo3/orm/issues/comments{/number}","contents_url":"https://api.github.com/repos/bravo3/orm/contents/{+path}","compare_url":"https://api.github.com/repos/bravo3/orm/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bravo3/orm/merges","archive_url":"https://api.github.com/repos/bravo3/orm/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bravo3/orm/downloads","issues_url":"https://api.github.com/repos/bravo3/orm/issues{/number}","pulls_url":"https://api.github.com/repos/bravo3/orm/pulls{/number}","milestones_url":"https://api.github.com/repos/bravo3/orm/milestones{/number}","notifications_url":"https://api.github.com/repos/bravo3/orm/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bravo3/orm/labels{/name}","releases_url":"https://api.github.com/repos/bravo3/orm/releases{/id}","created_at":"2014-12-19T02:36:35Z","updated_at":"2015-11-28T12:43:33Z","pushed_at":"2015-11-30T05:08:55Z","git_url":"git://github.com/bravo3/orm.git","ssh_url":"git@github.com:bravo3/orm.git","clone_url":"https://github.com/bravo3/orm.git","svn_url":"https://github.com/bravo3/orm","homepage":"","size":441,"stargazers_count":38,"watchers_count":38,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3,"mirror_url":null,"open_issues_count":3,"forks":3,"open_issues":3,"watchers":38,"default_branch":"master"}},"base":{"label":"bravo3:master","ref":"master","sha":"d0cf02ea32778e77a588d61a7aaf3fc15b3a0c5a","user":{"login":"bravo3","id":7390697,"avatar_url":"https://avatars.githubusercontent.com/u/7390697?v=3","gravatar_id":"","url":"https://api.github.com/users/bravo3","html_url":"https://github.com/bravo3","followers_url":"https://api.github.com/users/bravo3/followers","following_url":"https://api.github.com/users/bravo3/following{/other_user}","gists_url":"https://api.github.com/users/bravo3/gists{/gist_id}","starred_url":"https://api.github.com/users/bravo3/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bravo3/subscriptions","organizations_url":"https://api.github.com/users/bravo3/orgs","repos_url":"https://api.github.com/users/bravo3/repos","events_url":"https://api.github.com/users/bravo3/events{/privacy}","received_events_url":"https://api.github.com/users/bravo3/received_events","type":"Organization","site_admin":false},"repo":{"id":28211142,"name":"orm","full_name":"bravo3/orm","owner":{"login":"bravo3","id":7390697,"avatar_url":"https://avatars.githubusercontent.com/u/7390697?v=3","gravatar_id":"","url":"https://api.github.com/users/bravo3","html_url":"https://github.com/bravo3","followers_url":"https://api.github.com/users/bravo3/followers","following_url":"https://api.github.com/users/bravo3/following{/other_user}","gists_url":"https://api.github.com/users/bravo3/gists{/gist_id}","starred_url":"https://api.github.com/users/bravo3/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bravo3/subscriptions","organizations_url":"https://api.github.com/users/bravo3/orgs","repos_url":"https://api.github.com/users/bravo3/repos","events_url":"https://api.github.com/users/bravo3/events{/privacy}","received_events_url":"https://api.github.com/users/bravo3/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/bravo3/orm","description":"Document ORM for NoSQL databases like Redis","fork":false,"url":"https://api.github.com/repos/bravo3/orm","forks_url":"https://api.github.com/repos/bravo3/orm/forks","keys_url":"https://api.github.com/repos/bravo3/orm/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bravo3/orm/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bravo3/orm/teams","hooks_url":"https://api.github.com/repos/bravo3/orm/hooks","issue_events_url":"https://api.github.com/repos/bravo3/orm/issues/events{/number}","events_url":"https://api.github.com/repos/bravo3/orm/events","assignees_url":"https://api.github.com/repos/bravo3/orm/assignees{/user}","branches_url":"https://api.github.com/repos/bravo3/orm/branches{/branch}","tags_url":"https://api.github.com/repos/bravo3/orm/tags","blobs_url":"https://api.github.com/repos/bravo3/orm/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bravo3/orm/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bravo3/orm/git/refs{/sha}","trees_url":"https://api.github.com/repos/bravo3/orm/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bravo3/orm/statuses/{sha}","languages_url":"https://api.github.com/repos/bravo3/orm/languages","stargazers_url":"https://api.github.com/repos/bravo3/orm/stargazers","contributors_url":"https://api.github.com/repos/bravo3/orm/contributors","subscribers_url":"https://api.github.com/repos/bravo3/orm/subscribers","subscription_url":"https://api.github.com/repos/bravo3/orm/subscription","commits_url":"https://api.github.com/repos/bravo3/orm/commits{/sha}","git_commits_url":"https://api.github.com/repos/bravo3/orm/git/commits{/sha}","comments_url":"https://api.github.com/repos/bravo3/orm/comments{/number}","issue_comment_url":"https://api.github.com/repos/bravo3/orm/issues/comments{/number}","contents_url":"https://api.github.com/repos/bravo3/orm/contents/{+path}","compare_url":"https://api.github.com/repos/bravo3/orm/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bravo3/orm/merges","archive_url":"https://api.github.com/repos/bravo3/orm/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bravo3/orm/downloads","issues_url":"https://api.github.com/repos/bravo3/orm/issues{/number}","pulls_url":"https://api.github.com/repos/bravo3/orm/pulls{/number}","milestones_url":"https://api.github.com/repos/bravo3/orm/milestones{/number}","notifications_url":"https://api.github.com/repos/bravo3/orm/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bravo3/orm/labels{/name}","releases_url":"https://api.github.com/repos/bravo3/orm/releases{/id}","created_at":"2014-12-19T02:36:35Z","updated_at":"2015-11-28T12:43:33Z","pushed_at":"2015-11-30T05:08:55Z","git_url":"git://github.com/bravo3/orm.git","ssh_url":"git@github.com:bravo3/orm.git","clone_url":"https://github.com/bravo3/orm.git","svn_url":"https://github.com/bravo3/orm","homepage":"","size":441,"stargazers_count":38,"watchers_count":38,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3,"mirror_url":null,"open_issues_count":3,"forks":3,"open_issues":3,"watchers":38,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/bravo3/orm/pulls/37"},"html":{"href":"https://github.com/bravo3/orm/pull/37"},"issue":{"href":"https://api.github.com/repos/bravo3/orm/issues/37"},"comments":{"href":"https://api.github.com/repos/bravo3/orm/issues/37/comments"},"review_comments":{"href":"https://api.github.com/repos/bravo3/orm/pulls/37/comments"},"review_comment":{"href":"https://api.github.com/repos/bravo3/orm/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/bravo3/orm/pulls/37/commits"},"statuses":{"href":"https://api.github.com/repos/bravo3/orm/statuses/c96da7f738c892b4b4df7390e8e12943176d8534"}}}}