{"action":"created","comment":{"url":"https://api.github.com/repos/api-platform/docs/pulls/comments/75119179","id":75119179,"diff_hunk":"@@ -0,0 +1,99 @@\n+# Accept `application/x-www-form-urlencoded` Form Data\n+\n+## Create your `DeserializeListener` Decorator\n+\n+This decorator is able to denormalize posted form data to the target object. In case of other format, it fallbacks to the original [DeserializeListener](https://github.com/api-platform/core/blob/91dc2a4d6eeb79ea8dec26b41e800827336beb1a/src/Bridge/Symfony/Bundle/Resources/config/api.xml#L85-L91).\n+\n+```php\n+namespace AppBundle\\Listener;\n+\n+use ApiPlatform\\Core\\Exception\\RuntimeException;\n+use ApiPlatform\\Core\\Util\\RequestAttributesExtractor;\n+use Symfony\\Component\\HttpFoundation\\Request;\n+use Symfony\\Component\\HttpKernel\\Event\\GetResponseEvent;\n+use ApiPlatform\\Core\\EventListener\\DeserializeListener as DecoratedListener;\n+use Symfony\\Component\\Serializer\\Normalizer\\DenormalizerInterface;\n+use ApiPlatform\\Core\\Serializer\\SerializerContextBuilderInterface;\n+\n+class DeserializeListener\n+{\n+    private $decorated;\n+\n+    private $denormalizer;\n+\n+    private $serializerContextBuilder;\n+\n+    public function __construct(DecoratedListener $decorated, DenormalizerInterface $denormalizer, SerializerContextBuilderInterface $serializerContextBuilder)\n+    {\n+        $this->decorated = $decorated;\n+        $this->denormalizer = $denormalizer;\n+        $this->serializerContextBuilder = $serializerContextBuilder;\n+    }\n+\n+    public function onKernelRequest(GetResponseEvent $event) {\n+        $request = $event->getRequest();\n+        if ($request->isMethodSafe() || $request->isMethod(Request::METHOD_DELETE)) {\n+            return;\n+        }\n+\n+        if ('form' === $request->getContentType()) {\n+            $this->denormalizeFormRequest($request);\n+        } else {\n+            $this->decorated->onKernelRequest($event);\n+        }\n+    }\n+\n+    private function denormalizeFormRequest(Request $request)\n+    {\n+        try {\n+            $attributes = RequestAttributesExtractor::extractAttributes($request);\n+        } catch (RuntimeException $e) {\n+            return;\n+        }\n+        $context = $this->serializerContextBuilder->createFromRequest($request, false, $attributes);\n+        $data = $request->request->all();\n+        $object = $this->denormalizer->denormalize($data, $attributes['resource_class'], null, $context);\n+        $request->attributes->set('data', $object);\n+    }\n+}\n+```\n+\n+## Create the service definition\n+\n+```yaml\n+# app/config/services.yml\n+services:\n+    # ...\n+    app.listener.decorating_deserialize:\n+        class: 'AppBundle\\Listener\\DeserializeListener'\n+        arguments: ['@api_platform.listener.request.deserialize', '@api_platform.serializer', '@api_platform.serializer.context_builder']\n+        tags:\n+            - { name: 'kernel.event_listener', event: 'kernel.request', method: 'onKernelRequest', priority: 2 }","path":"core/form-data.md","position":71,"original_position":71,"commit_id":"5877c3b366881e515ee5c7b032c06738ad6ec180","original_commit_id":"5877c3b366881e515ee5c7b032c06738ad6ec180","user":{"login":"teohhanhui","id":548843,"avatar_url":"https://avatars.githubusercontent.com/u/548843?v=3","gravatar_id":"","url":"https://api.github.com/users/teohhanhui","html_url":"https://github.com/teohhanhui","followers_url":"https://api.github.com/users/teohhanhui/followers","following_url":"https://api.github.com/users/teohhanhui/following{/other_user}","gists_url":"https://api.github.com/users/teohhanhui/gists{/gist_id}","starred_url":"https://api.github.com/users/teohhanhui/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/teohhanhui/subscriptions","organizations_url":"https://api.github.com/users/teohhanhui/orgs","repos_url":"https://api.github.com/users/teohhanhui/repos","events_url":"https://api.github.com/users/teohhanhui/events{/privacy}","received_events_url":"https://api.github.com/users/teohhanhui/received_events","type":"User","site_admin":false},"body":"Try removing the tag and making the decorator service `public: false`.\r\n\r\nThe [Symfony docs](http://symfony.com/doc/current/service_container/service_decoration.html) says:\r\n> The visibility of the decorated ... service (which is an alias for the new service) will still be the same as the original ... visibility.","created_at":"2016-08-17T13:14:30Z","updated_at":"2016-08-17T13:14:30Z","html_url":"https://github.com/api-platform/docs/pull/99#discussion_r75119179","pull_request_url":"https://api.github.com/repos/api-platform/docs/pulls/99","_links":{"self":{"href":"https://api.github.com/repos/api-platform/docs/pulls/comments/75119179"},"html":{"href":"https://github.com/api-platform/docs/pull/99#discussion_r75119179"},"pull_request":{"href":"https://api.github.com/repos/api-platform/docs/pulls/99"}}},"pull_request":{"url":"https://api.github.com/repos/api-platform/docs/pulls/99","id":80583972,"html_url":"https://github.com/api-platform/docs/pull/99","diff_url":"https://github.com/api-platform/docs/pull/99.diff","patch_url":"https://github.com/api-platform/docs/pull/99.patch","issue_url":"https://api.github.com/repos/api-platform/docs/issues/99","number":99,"state":"open","locked":false,"title":"How to accept posted form data","user":{"login":"karser","id":1675033,"avatar_url":"https://avatars.githubusercontent.com/u/1675033?v=3","gravatar_id":"","url":"https://api.github.com/users/karser","html_url":"https://github.com/karser","followers_url":"https://api.github.com/users/karser/followers","following_url":"https://api.github.com/users/karser/following{/other_user}","gists_url":"https://api.github.com/users/karser/gists{/gist_id}","starred_url":"https://api.github.com/users/karser/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/karser/subscriptions","organizations_url":"https://api.github.com/users/karser/orgs","repos_url":"https://api.github.com/users/karser/repos","events_url":"https://api.github.com/users/karser/events{/privacy}","received_events_url":"https://api.github.com/users/karser/received_events","type":"User","site_admin":false},"body":"https://github.com/api-platform/core/issues/674","created_at":"2016-08-09T08:57:50Z","updated_at":"2016-08-17T13:14:30Z","closed_at":null,"merged_at":null,"merge_commit_sha":"5645bf00942aa7b6a6d0896fbc45e0f728918255","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/api-platform/docs/pulls/99/commits","review_comments_url":"https://api.github.com/repos/api-platform/docs/pulls/99/comments","review_comment_url":"https://api.github.com/repos/api-platform/docs/pulls/comments{/number}","comments_url":"https://api.github.com/repos/api-platform/docs/issues/99/comments","statuses_url":"https://api.github.com/repos/api-platform/docs/statuses/5877c3b366881e515ee5c7b032c06738ad6ec180","head":{"label":"karser:accept-form-data","ref":"accept-form-data","sha":"5877c3b366881e515ee5c7b032c06738ad6ec180","user":{"login":"karser","id":1675033,"avatar_url":"https://avatars.githubusercontent.com/u/1675033?v=3","gravatar_id":"","url":"https://api.github.com/users/karser","html_url":"https://github.com/karser","followers_url":"https://api.github.com/users/karser/followers","following_url":"https://api.github.com/users/karser/following{/other_user}","gists_url":"https://api.github.com/users/karser/gists{/gist_id}","starred_url":"https://api.github.com/users/karser/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/karser/subscriptions","organizations_url":"https://api.github.com/users/karser/orgs","repos_url":"https://api.github.com/users/karser/repos","events_url":"https://api.github.com/users/karser/events{/privacy}","received_events_url":"https://api.github.com/users/karser/received_events","type":"User","site_admin":false},"repo":{"id":65277161,"name":"docs","full_name":"karser/docs","owner":{"login":"karser","id":1675033,"avatar_url":"https://avatars.githubusercontent.com/u/1675033?v=3","gravatar_id":"","url":"https://api.github.com/users/karser","html_url":"https://github.com/karser","followers_url":"https://api.github.com/users/karser/followers","following_url":"https://api.github.com/users/karser/following{/other_user}","gists_url":"https://api.github.com/users/karser/gists{/gist_id}","starred_url":"https://api.github.com/users/karser/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/karser/subscriptions","organizations_url":"https://api.github.com/users/karser/orgs","repos_url":"https://api.github.com/users/karser/repos","events_url":"https://api.github.com/users/karser/events{/privacy}","received_events_url":"https://api.github.com/users/karser/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/karser/docs","description":"API Platform documentation","fork":true,"url":"https://api.github.com/repos/karser/docs","forks_url":"https://api.github.com/repos/karser/docs/forks","keys_url":"https://api.github.com/repos/karser/docs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/karser/docs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/karser/docs/teams","hooks_url":"https://api.github.com/repos/karser/docs/hooks","issue_events_url":"https://api.github.com/repos/karser/docs/issues/events{/number}","events_url":"https://api.github.com/repos/karser/docs/events","assignees_url":"https://api.github.com/repos/karser/docs/assignees{/user}","branches_url":"https://api.github.com/repos/karser/docs/branches{/branch}","tags_url":"https://api.github.com/repos/karser/docs/tags","blobs_url":"https://api.github.com/repos/karser/docs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/karser/docs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/karser/docs/git/refs{/sha}","trees_url":"https://api.github.com/repos/karser/docs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/karser/docs/statuses/{sha}","languages_url":"https://api.github.com/repos/karser/docs/languages","stargazers_url":"https://api.github.com/repos/karser/docs/stargazers","contributors_url":"https://api.github.com/repos/karser/docs/contributors","subscribers_url":"https://api.github.com/repos/karser/docs/subscribers","subscription_url":"https://api.github.com/repos/karser/docs/subscription","commits_url":"https://api.github.com/repos/karser/docs/commits{/sha}","git_commits_url":"https://api.github.com/repos/karser/docs/git/commits{/sha}","comments_url":"https://api.github.com/repos/karser/docs/comments{/number}","issue_comment_url":"https://api.github.com/repos/karser/docs/issues/comments{/number}","contents_url":"https://api.github.com/repos/karser/docs/contents/{+path}","compare_url":"https://api.github.com/repos/karser/docs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/karser/docs/merges","archive_url":"https://api.github.com/repos/karser/docs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/karser/docs/downloads","issues_url":"https://api.github.com/repos/karser/docs/issues{/number}","pulls_url":"https://api.github.com/repos/karser/docs/pulls{/number}","milestones_url":"https://api.github.com/repos/karser/docs/milestones{/number}","notifications_url":"https://api.github.com/repos/karser/docs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/karser/docs/labels{/name}","releases_url":"https://api.github.com/repos/karser/docs/releases{/id}","deployments_url":"https://api.github.com/repos/karser/docs/deployments","created_at":"2016-08-09T08:25:21Z","updated_at":"2016-07-30T14:53:58Z","pushed_at":"2016-08-17T11:41:46Z","git_url":"git://github.com/karser/docs.git","ssh_url":"git@github.com:karser/docs.git","clone_url":"https://github.com/karser/docs.git","svn_url":"https://github.com/karser/docs","homepage":"https://api-platform.com/doc/","size":701,"stargazers_count":0,"watchers_count":0,"language":null,"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":"fe73c4c93c3057949b6619a9b058dc2829d2078b","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":38251565,"name":"docs","full_name":"api-platform/docs","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/docs","description":"API Platform documentation","fork":false,"url":"https://api.github.com/repos/api-platform/docs","forks_url":"https://api.github.com/repos/api-platform/docs/forks","keys_url":"https://api.github.com/repos/api-platform/docs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/api-platform/docs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/api-platform/docs/teams","hooks_url":"https://api.github.com/repos/api-platform/docs/hooks","issue_events_url":"https://api.github.com/repos/api-platform/docs/issues/events{/number}","events_url":"https://api.github.com/repos/api-platform/docs/events","assignees_url":"https://api.github.com/repos/api-platform/docs/assignees{/user}","branches_url":"https://api.github.com/repos/api-platform/docs/branches{/branch}","tags_url":"https://api.github.com/repos/api-platform/docs/tags","blobs_url":"https://api.github.com/repos/api-platform/docs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/api-platform/docs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/api-platform/docs/git/refs{/sha}","trees_url":"https://api.github.com/repos/api-platform/docs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/api-platform/docs/statuses/{sha}","languages_url":"https://api.github.com/repos/api-platform/docs/languages","stargazers_url":"https://api.github.com/repos/api-platform/docs/stargazers","contributors_url":"https://api.github.com/repos/api-platform/docs/contributors","subscribers_url":"https://api.github.com/repos/api-platform/docs/subscribers","subscription_url":"https://api.github.com/repos/api-platform/docs/subscription","commits_url":"https://api.github.com/repos/api-platform/docs/commits{/sha}","git_commits_url":"https://api.github.com/repos/api-platform/docs/git/commits{/sha}","comments_url":"https://api.github.com/repos/api-platform/docs/comments{/number}","issue_comment_url":"https://api.github.com/repos/api-platform/docs/issues/comments{/number}","contents_url":"https://api.github.com/repos/api-platform/docs/contents/{+path}","compare_url":"https://api.github.com/repos/api-platform/docs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/api-platform/docs/merges","archive_url":"https://api.github.com/repos/api-platform/docs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/api-platform/docs/downloads","issues_url":"https://api.github.com/repos/api-platform/docs/issues{/number}","pulls_url":"https://api.github.com/repos/api-platform/docs/pulls{/number}","milestones_url":"https://api.github.com/repos/api-platform/docs/milestones{/number}","notifications_url":"https://api.github.com/repos/api-platform/docs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/api-platform/docs/labels{/name}","releases_url":"https://api.github.com/repos/api-platform/docs/releases{/id}","deployments_url":"https://api.github.com/repos/api-platform/docs/deployments","created_at":"2015-06-29T14:19:34Z","updated_at":"2016-08-10T07:34:05Z","pushed_at":"2016-08-17T13:07:41Z","git_url":"git://github.com/api-platform/docs.git","ssh_url":"git@github.com:api-platform/docs.git","clone_url":"https://github.com/api-platform/docs.git","svn_url":"https://github.com/api-platform/docs","homepage":"https://api-platform.com/doc/","size":741,"stargazers_count":20,"watchers_count":20,"language":null,"has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":31,"mirror_url":null,"open_issues_count":8,"forks":31,"open_issues":8,"watchers":20,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/api-platform/docs/pulls/99"},"html":{"href":"https://github.com/api-platform/docs/pull/99"},"issue":{"href":"https://api.github.com/repos/api-platform/docs/issues/99"},"comments":{"href":"https://api.github.com/repos/api-platform/docs/issues/99/comments"},"review_comments":{"href":"https://api.github.com/repos/api-platform/docs/pulls/99/comments"},"review_comment":{"href":"https://api.github.com/repos/api-platform/docs/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/api-platform/docs/pulls/99/commits"},"statuses":{"href":"https://api.github.com/repos/api-platform/docs/statuses/5877c3b366881e515ee5c7b032c06738ad6ec180"}}}}
{"actor":{"display_login":"teohhanhui"}}