{"action":"created","comment":{"url":"https://api.github.com/repos/api-platform/core/pulls/comments/85119815","pull_request_review_id":5853020,"id":85119815,"diff_hunk":"@@ -0,0 +1,199 @@\n+<?php\n+\n+/*\n+ * This file is part of the API Platform project.\n+ *\n+ * (c) Kévin Dunglas <dunglas@gmail.com>\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 ApiPlatform\\Core\\Metadata\\Property\\Factory;\n+\n+use ApiPlatform\\Core\\Exception\\InvalidArgumentException;\n+use ApiPlatform\\Core\\Exception\\PropertyNotFoundException;\n+use ApiPlatform\\Core\\Metadata\\Property\\PropertyMetadata;\n+use Symfony\\Component\\Yaml\\Exception\\ParseException;\n+use Symfony\\Component\\Yaml\\Yaml;\n+\n+/**\n+ * Creates a property metadata from YAML {@see Property} configuration files.\n+ *\n+ * @author Baptiste Meyer <baptiste.meyer@gmail.com>\n+ */\n+class YamlPropertyMetadataFactory implements PropertyMetadataFactoryInterface\n+{\n+    private $paths;\n+    private $decorated;\n+\n+    /**\n+     * @param array                                 $paths\n+     * @param PropertyMetadataFactoryInterface|null $decorated\n+     */\n+    public function __construct(array $paths, PropertyMetadataFactoryInterface $decorated = null)\n+    {\n+        $this->paths = $paths;\n+        $this->decorated = $decorated;\n+    }\n+\n+    /**\n+     * {@inheritdoc}\n+     */\n+    public function create(string $resourceClass, string $property, array $options = []) : PropertyMetadata\n+    {\n+        $parentPropertyMetadata = null;\n+        if ($this->decorated) {\n+            try {\n+                $parentPropertyMetadata = $this->decorated->create($resourceClass, $property, $options);\n+            } catch (PropertyNotFoundException $propertyNotFoundException) {\n+                // Ignore not found exception from decorated factories\n+            }\n+        }\n+\n+        if (!class_exists($resourceClass) || !property_exists($resourceClass, $property) || empty($propertyMetadata = $this->getMetadata($resourceClass, $property))) {\n+            return $this->handleNotFound($parentPropertyMetadata, $resourceClass, $property);\n+        }\n+\n+        if ($parentPropertyMetadata) {\n+            return $this->update($parentPropertyMetadata, $propertyMetadata);\n+        }\n+\n+        return new PropertyMetadata(\n+            null,\n+            $propertyMetadata['description'],\n+            $propertyMetadata['readable'],\n+            $propertyMetadata['writable'],\n+            $propertyMetadata['readableLink'],\n+            $propertyMetadata['writableLink'],\n+            $propertyMetadata['required'],\n+            $propertyMetadata['identifier'],\n+            $propertyMetadata['iri'],\n+            null,\n+            $propertyMetadata['attributes']\n+        );\n+    }\n+\n+    /**\n+     * Returns the metadata from the decorated factory if available or throws an exception.\n+     *\n+     * @param PropertyMetadata|null $parentPropertyMetadata\n+     * @param string                $resourceClass\n+     * @param string                $property\n+     *\n+     * @throws PropertyNotFoundException\n+     *\n+     * @return PropertyMetadata\n+     */\n+    private function handleNotFound(PropertyMetadata $parentPropertyMetadata = null, string $resourceClass, string $property) : PropertyMetadata\n+    {\n+        if ($parentPropertyMetadata) {\n+            return $parentPropertyMetadata;\n+        }\n+\n+        throw new PropertyNotFoundException(sprintf('Property \"%s\" of the resource class \"%s\" not found.', $property, $resourceClass));\n+    }\n+\n+    /**\n+     * Extracts metadata from the YAML tree.\n+     *\n+     * @param string $resourceClass\n+     * @param string $property\n+     *\n+     * @throws ParseException\n+     * @throws InvalidArgumentException\n+     *\n+     * @return array\n+     */\n+    private function getMetadata(string $resourceClass, string $property) : array\n+    {\n+        foreach ($this->paths as $path) {\n+            try {\n+                $resources = Yaml::parse(file_get_contents($path));\n+            } catch (ParseException $parseException) {\n+                $parseException->setParsedFile($path);\n+\n+                throw $parseException;\n+            }","path":"src/Metadata/Property/Factory/YamlPropertyMetadataFactory.php","position":117,"original_position":117,"commit_id":"865cb4205e49ec8161ad325af0dd555c3e2628b4","original_commit_id":"c528c9290c8caafc1edce83b9f9438fe7487fcc6","user":{"login":"meyerbaptiste","id":4034907,"avatar_url":"https://avatars.githubusercontent.com/u/4034907?v=3","gravatar_id":"","url":"https://api.github.com/users/meyerbaptiste","html_url":"https://github.com/meyerbaptiste","followers_url":"https://api.github.com/users/meyerbaptiste/followers","following_url":"https://api.github.com/users/meyerbaptiste/following{/other_user}","gists_url":"https://api.github.com/users/meyerbaptiste/gists{/gist_id}","starred_url":"https://api.github.com/users/meyerbaptiste/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/meyerbaptiste/subscriptions","organizations_url":"https://api.github.com/users/meyerbaptiste/orgs","repos_url":"https://api.github.com/users/meyerbaptiste/repos","events_url":"https://api.github.com/users/meyerbaptiste/events{/privacy}","received_events_url":"https://api.github.com/users/meyerbaptiste/received_events","type":"User","site_admin":false},"body":"Done :)","created_at":"2016-10-26T13:22:20Z","updated_at":"2016-10-26T13:22:20Z","html_url":"https://github.com/api-platform/core/pull/814#discussion_r85119815","pull_request_url":"https://api.github.com/repos/api-platform/core/pulls/814","_links":{"self":{"href":"https://api.github.com/repos/api-platform/core/pulls/comments/85119815"},"html":{"href":"https://github.com/api-platform/core/pull/814#discussion_r85119815"},"pull_request":{"href":"https://api.github.com/repos/api-platform/core/pulls/814"}}},"pull_request":{"url":"https://api.github.com/repos/api-platform/core/pulls/814","id":90379121,"html_url":"https://github.com/api-platform/core/pull/814","diff_url":"https://github.com/api-platform/core/pull/814.diff","patch_url":"https://github.com/api-platform/core/pull/814.patch","issue_url":"https://api.github.com/repos/api-platform/core/issues/814","number":814,"state":"open","locked":false,"title":"Support mapping properties in XML and YAML","user":{"login":"meyerbaptiste","id":4034907,"avatar_url":"https://avatars.githubusercontent.com/u/4034907?v=3","gravatar_id":"","url":"https://api.github.com/users/meyerbaptiste","html_url":"https://github.com/meyerbaptiste","followers_url":"https://api.github.com/users/meyerbaptiste/followers","following_url":"https://api.github.com/users/meyerbaptiste/following{/other_user}","gists_url":"https://api.github.com/users/meyerbaptiste/gists{/gist_id}","starred_url":"https://api.github.com/users/meyerbaptiste/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/meyerbaptiste/subscriptions","organizations_url":"https://api.github.com/users/meyerbaptiste/orgs","repos_url":"https://api.github.com/users/meyerbaptiste/repos","events_url":"https://api.github.com/users/meyerbaptiste/events{/privacy}","received_events_url":"https://api.github.com/users/meyerbaptiste/received_events","type":"User","site_admin":false},"body":"| Q             | A\r\n| ------------- | ---\r\n| Bug fix?      | no\r\n| New feature?  | yes\r\n| BC breaks?    | no\r\n| Deprecations? | no\r\n| Tests pass?   | yes\r\n| Fixed tickets | #739, api-platform/api-platform#140\r\n| License       | MIT\r\n| Doc PR        | N/A\r\n\r\nThis PR adds support of mapping for properties in XML and YAML.\r\nI followed the recommendations from #421.\r\n","created_at":"2016-10-21T13:10:15Z","updated_at":"2016-10-26T13:22:20Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d7bda4e7a0c325d7b78f7a61ca852b0eafdcdb10","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/api-platform/core/pulls/814/commits","review_comments_url":"https://api.github.com/repos/api-platform/core/pulls/814/comments","review_comment_url":"https://api.github.com/repos/api-platform/core/pulls/comments{/number}","comments_url":"https://api.github.com/repos/api-platform/core/issues/814/comments","statuses_url":"https://api.github.com/repos/api-platform/core/statuses/865cb4205e49ec8161ad325af0dd555c3e2628b4","head":{"label":"meyerbaptiste:add_xml_yml_property_configuration","ref":"add_xml_yml_property_configuration","sha":"865cb4205e49ec8161ad325af0dd555c3e2628b4","user":{"login":"meyerbaptiste","id":4034907,"avatar_url":"https://avatars.githubusercontent.com/u/4034907?v=3","gravatar_id":"","url":"https://api.github.com/users/meyerbaptiste","html_url":"https://github.com/meyerbaptiste","followers_url":"https://api.github.com/users/meyerbaptiste/followers","following_url":"https://api.github.com/users/meyerbaptiste/following{/other_user}","gists_url":"https://api.github.com/users/meyerbaptiste/gists{/gist_id}","starred_url":"https://api.github.com/users/meyerbaptiste/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/meyerbaptiste/subscriptions","organizations_url":"https://api.github.com/users/meyerbaptiste/orgs","repos_url":"https://api.github.com/users/meyerbaptiste/repos","events_url":"https://api.github.com/users/meyerbaptiste/events{/privacy}","received_events_url":"https://api.github.com/users/meyerbaptiste/received_events","type":"User","site_admin":false},"repo":{"id":68818371,"name":"core","full_name":"meyerbaptiste/core","owner":{"login":"meyerbaptiste","id":4034907,"avatar_url":"https://avatars.githubusercontent.com/u/4034907?v=3","gravatar_id":"","url":"https://api.github.com/users/meyerbaptiste","html_url":"https://github.com/meyerbaptiste","followers_url":"https://api.github.com/users/meyerbaptiste/followers","following_url":"https://api.github.com/users/meyerbaptiste/following{/other_user}","gists_url":"https://api.github.com/users/meyerbaptiste/gists{/gist_id}","starred_url":"https://api.github.com/users/meyerbaptiste/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/meyerbaptiste/subscriptions","organizations_url":"https://api.github.com/users/meyerbaptiste/orgs","repos_url":"https://api.github.com/users/meyerbaptiste/repos","events_url":"https://api.github.com/users/meyerbaptiste/events{/privacy}","received_events_url":"https://api.github.com/users/meyerbaptiste/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/meyerbaptiste/core","description":"The Hypermedia REST API component of API Platform: JSON-LD and Hydra support, works with Symfony too","fork":true,"url":"https://api.github.com/repos/meyerbaptiste/core","forks_url":"https://api.github.com/repos/meyerbaptiste/core/forks","keys_url":"https://api.github.com/repos/meyerbaptiste/core/keys{/key_id}","collaborators_url":"https://api.github.com/repos/meyerbaptiste/core/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/meyerbaptiste/core/teams","hooks_url":"https://api.github.com/repos/meyerbaptiste/core/hooks","issue_events_url":"https://api.github.com/repos/meyerbaptiste/core/issues/events{/number}","events_url":"https://api.github.com/repos/meyerbaptiste/core/events","assignees_url":"https://api.github.com/repos/meyerbaptiste/core/assignees{/user}","branches_url":"https://api.github.com/repos/meyerbaptiste/core/branches{/branch}","tags_url":"https://api.github.com/repos/meyerbaptiste/core/tags","blobs_url":"https://api.github.com/repos/meyerbaptiste/core/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/meyerbaptiste/core/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/meyerbaptiste/core/git/refs{/sha}","trees_url":"https://api.github.com/repos/meyerbaptiste/core/git/trees{/sha}","statuses_url":"https://api.github.com/repos/meyerbaptiste/core/statuses/{sha}","languages_url":"https://api.github.com/repos/meyerbaptiste/core/languages","stargazers_url":"https://api.github.com/repos/meyerbaptiste/core/stargazers","contributors_url":"https://api.github.com/repos/meyerbaptiste/core/contributors","subscribers_url":"https://api.github.com/repos/meyerbaptiste/core/subscribers","subscription_url":"https://api.github.com/repos/meyerbaptiste/core/subscription","commits_url":"https://api.github.com/repos/meyerbaptiste/core/commits{/sha}","git_commits_url":"https://api.github.com/repos/meyerbaptiste/core/git/commits{/sha}","comments_url":"https://api.github.com/repos/meyerbaptiste/core/comments{/number}","issue_comment_url":"https://api.github.com/repos/meyerbaptiste/core/issues/comments{/number}","contents_url":"https://api.github.com/repos/meyerbaptiste/core/contents/{+path}","compare_url":"https://api.github.com/repos/meyerbaptiste/core/compare/{base}...{head}","merges_url":"https://api.github.com/repos/meyerbaptiste/core/merges","archive_url":"https://api.github.com/repos/meyerbaptiste/core/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/meyerbaptiste/core/downloads","issues_url":"https://api.github.com/repos/meyerbaptiste/core/issues{/number}","pulls_url":"https://api.github.com/repos/meyerbaptiste/core/pulls{/number}","milestones_url":"https://api.github.com/repos/meyerbaptiste/core/milestones{/number}","notifications_url":"https://api.github.com/repos/meyerbaptiste/core/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/meyerbaptiste/core/labels{/name}","releases_url":"https://api.github.com/repos/meyerbaptiste/core/releases{/id}","deployments_url":"https://api.github.com/repos/meyerbaptiste/core/deployments","created_at":"2016-09-21T13:14:50Z","updated_at":"2016-09-21T13:14:52Z","pushed_at":"2016-10-26T13:04:18Z","git_url":"git://github.com/meyerbaptiste/core.git","ssh_url":"git@github.com:meyerbaptiste/core.git","clone_url":"https://github.com/meyerbaptiste/core.git","svn_url":"https://github.com/meyerbaptiste/core","homepage":"https://api-platform.com","size":3700,"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":"api-platform:master","ref":"master","sha":"42e6b08c332270451535bde855c5a56ecf77aac6","user":{"login":"api-platform","id":13420081,"avatar_url":"https://avatars.githubusercontent.com/u/13420081?v=3","gravatar_id":"","url":"https://api.github.com/users/api-platform","html_url":"https://github.com/api-platform","followers_url":"https://api.github.com/users/api-platform/followers","following_url":"https://api.github.com/users/api-platform/following{/other_user}","gists_url":"https://api.github.com/users/api-platform/gists{/gist_id}","starred_url":"https://api.github.com/users/api-platform/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/api-platform/subscriptions","organizations_url":"https://api.github.com/users/api-platform/orgs","repos_url":"https://api.github.com/users/api-platform/repos","events_url":"https://api.github.com/users/api-platform/events{/privacy}","received_events_url":"https://api.github.com/users/api-platform/received_events","type":"Organization","site_admin":false},"repo":{"id":29501260,"name":"core","full_name":"api-platform/core","owner":{"login":"api-platform","id":13420081,"avatar_url":"https://avatars.githubusercontent.com/u/13420081?v=3","gravatar_id":"","url":"https://api.github.com/users/api-platform","html_url":"https://github.com/api-platform","followers_url":"https://api.github.com/users/api-platform/followers","following_url":"https://api.github.com/users/api-platform/following{/other_user}","gists_url":"https://api.github.com/users/api-platform/gists{/gist_id}","starred_url":"https://api.github.com/users/api-platform/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/api-platform/subscriptions","organizations_url":"https://api.github.com/users/api-platform/orgs","repos_url":"https://api.github.com/users/api-platform/repos","events_url":"https://api.github.com/users/api-platform/events{/privacy}","received_events_url":"https://api.github.com/users/api-platform/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/api-platform/core","description":"The Hypermedia REST API component of API Platform: JSON-LD and Hydra support, works with Symfony too","fork":false,"url":"https://api.github.com/repos/api-platform/core","forks_url":"https://api.github.com/repos/api-platform/core/forks","keys_url":"https://api.github.com/repos/api-platform/core/keys{/key_id}","collaborators_url":"https://api.github.com/repos/api-platform/core/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/api-platform/core/teams","hooks_url":"https://api.github.com/repos/api-platform/core/hooks","issue_events_url":"https://api.github.com/repos/api-platform/core/issues/events{/number}","events_url":"https://api.github.com/repos/api-platform/core/events","assignees_url":"https://api.github.com/repos/api-platform/core/assignees{/user}","branches_url":"https://api.github.com/repos/api-platform/core/branches{/branch}","tags_url":"https://api.github.com/repos/api-platform/core/tags","blobs_url":"https://api.github.com/repos/api-platform/core/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/api-platform/core/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/api-platform/core/git/refs{/sha}","trees_url":"https://api.github.com/repos/api-platform/core/git/trees{/sha}","statuses_url":"https://api.github.com/repos/api-platform/core/statuses/{sha}","languages_url":"https://api.github.com/repos/api-platform/core/languages","stargazers_url":"https://api.github.com/repos/api-platform/core/stargazers","contributors_url":"https://api.github.com/repos/api-platform/core/contributors","subscribers_url":"https://api.github.com/repos/api-platform/core/subscribers","subscription_url":"https://api.github.com/repos/api-platform/core/subscription","commits_url":"https://api.github.com/repos/api-platform/core/commits{/sha}","git_commits_url":"https://api.github.com/repos/api-platform/core/git/commits{/sha}","comments_url":"https://api.github.com/repos/api-platform/core/comments{/number}","issue_comment_url":"https://api.github.com/repos/api-platform/core/issues/comments{/number}","contents_url":"https://api.github.com/repos/api-platform/core/contents/{+path}","compare_url":"https://api.github.com/repos/api-platform/core/compare/{base}...{head}","merges_url":"https://api.github.com/repos/api-platform/core/merges","archive_url":"https://api.github.com/repos/api-platform/core/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/api-platform/core/downloads","issues_url":"https://api.github.com/repos/api-platform/core/issues{/number}","pulls_url":"https://api.github.com/repos/api-platform/core/pulls{/number}","milestones_url":"https://api.github.com/repos/api-platform/core/milestones{/number}","notifications_url":"https://api.github.com/repos/api-platform/core/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/api-platform/core/labels{/name}","releases_url":"https://api.github.com/repos/api-platform/core/releases{/id}","deployments_url":"https://api.github.com/repos/api-platform/core/deployments","created_at":"2015-01-19T23:05:56Z","updated_at":"2016-10-25T14:41:29Z","pushed_at":"2016-10-26T13:04:19Z","git_url":"git://github.com/api-platform/core.git","ssh_url":"git@github.com:api-platform/core.git","clone_url":"https://github.com/api-platform/core.git","svn_url":"https://github.com/api-platform/core","homepage":"https://api-platform.com","size":4505,"stargazers_count":356,"watchers_count":356,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":99,"mirror_url":null,"open_issues_count":64,"forks":99,"open_issues":64,"watchers":356,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/api-platform/core/pulls/814"},"html":{"href":"https://github.com/api-platform/core/pull/814"},"issue":{"href":"https://api.github.com/repos/api-platform/core/issues/814"},"comments":{"href":"https://api.github.com/repos/api-platform/core/issues/814/comments"},"review_comments":{"href":"https://api.github.com/repos/api-platform/core/pulls/814/comments"},"review_comment":{"href":"https://api.github.com/repos/api-platform/core/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/api-platform/core/pulls/814/commits"},"statuses":{"href":"https://api.github.com/repos/api-platform/core/statuses/865cb4205e49ec8161ad325af0dd555c3e2628b4"}}}}
{"actor":{"display_login":"meyerbaptiste"}}