{"action":"created","comment":{"url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/pulls/comments/49892262","id":49892262,"diff_hunk":"@@ -0,0 +1,56 @@\n+<?php\n+\n+/*\n+ * This file is part of the FOSRestBundle package.\n+ *\n+ * (c) FriendsOfSymfony <http://friendsofsymfony.github.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 FOS\\RestBundle\\Form\\Transformer;\n+\n+use Symfony\\Component\\Form\\DataTransformerInterface;\n+use Symfony\\Component\\Form\\Exception\\TransformationFailedException;\n+\n+/**\n+ * @author GeLo <geloen.eric@gmail.com>\n+ */\n+class BooleanTypeToBooleanTransformer implements DataTransformerInterface\n+{\n+    /**\n+     * {@inheritdoc}\n+     */\n+    public function transform($value)\n+    {\n+        if ($value === null) {\n+            return;\n+        }\n+\n+        if (!is_bool($value)) {\n+            throw new TransformationFailedException(sprintf(\n+                'The boolean type expects a boolean or null value, got \"%s\"',\n+                is_object($value) ? get_class($value) : gettype($value)\n+            ));\n+        }\n+\n+        return $value;\n+    }\n+\n+    /**\n+     * {@inheritdoc}\n+     */\n+    public function reverseTransform($value)\n+    {\n+        $filterValue = !is_object($value)\n+            ? filter_var($value, FILTER_VALIDATE_BOOLEAN, array('flags' => FILTER_NULL_ON_FAILURE))\n+            : $value;","path":"Form/Transformer/BooleanTypeToBooleanTransformer.php","position":48,"original_position":48,"commit_id":"468315562b28efb80d34c232624f36d9082af66c","original_commit_id":"468315562b28efb80d34c232624f36d9082af66c","user":{"login":"egeloen","id":737992,"avatar_url":"https://avatars.githubusercontent.com/u/737992?v=3","gravatar_id":"","url":"https://api.github.com/users/egeloen","html_url":"https://github.com/egeloen","followers_url":"https://api.github.com/users/egeloen/followers","following_url":"https://api.github.com/users/egeloen/following{/other_user}","gists_url":"https://api.github.com/users/egeloen/gists{/gist_id}","starred_url":"https://api.github.com/users/egeloen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/egeloen/subscriptions","organizations_url":"https://api.github.com/users/egeloen/orgs","repos_url":"https://api.github.com/users/egeloen/repos","events_url":"https://api.github.com/users/egeloen/events{/privacy}","received_events_url":"https://api.github.com/users/egeloen/received_events","type":"User","site_admin":false},"body":"I'm not really fan of this block but it seems `filter_var` is buggy with object.\r\n\r\nQuoting the doc:\r\n\r\n> Returns TRUE for \"1\", \"true\", \"on\" and \"yes\". Returns FALSE otherwise.\r\n>\r\n> If FILTER_NULL_ON_FAILURE is set, FALSE is returned only for \"0\", \"false\", \"off\", \"no\", and \"\", and NULL is returned for all non-boolean values.\r\n\r\nUnfortunatelly, passing an `\\stdClass` (as it is done in the tests) returns `false` instead of `null`. So I workaround it this way for now...","created_at":"2016-01-15T19:10:42Z","updated_at":"2016-01-15T19:10:42Z","html_url":"https://github.com/FriendsOfSymfony/FOSRestBundle/pull/1312#discussion_r49892262","pull_request_url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/pulls/1312","_links":{"self":{"href":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/pulls/comments/49892262"},"html":{"href":"https://github.com/FriendsOfSymfony/FOSRestBundle/pull/1312#discussion_r49892262"},"pull_request":{"href":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/pulls/1312"}}},"pull_request":{"url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/pulls/1312","id":56089845,"html_url":"https://github.com/FriendsOfSymfony/FOSRestBundle/pull/1312","diff_url":"https://github.com/FriendsOfSymfony/FOSRestBundle/pull/1312.diff","patch_url":"https://github.com/FriendsOfSymfony/FOSRestBundle/pull/1312.patch","issue_url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/issues/1312","number":1312,"state":"open","locked":false,"title":"Add boolean extension support","user":{"login":"egeloen","id":737992,"avatar_url":"https://avatars.githubusercontent.com/u/737992?v=3","gravatar_id":"","url":"https://api.github.com/users/egeloen","html_url":"https://github.com/egeloen","followers_url":"https://api.github.com/users/egeloen/followers","following_url":"https://api.github.com/users/egeloen/following{/other_user}","gists_url":"https://api.github.com/users/egeloen/gists{/gist_id}","starred_url":"https://api.github.com/users/egeloen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/egeloen/subscriptions","organizations_url":"https://api.github.com/users/egeloen/orgs","repos_url":"https://api.github.com/users/egeloen/repos","events_url":"https://api.github.com/users/egeloen/events{/privacy}","received_events_url":"https://api.github.com/users/egeloen/received_events","type":"User","site_admin":false},"body":"Hey!\r\n\r\nI was starting wrting this piece of text and realize there is #1295... Anyway, as it is done let's share it and additionally, I'm not really in favor of #1295. Instead, I propose this one which is more strict on the submitted value. IMO, in a API context, if a user sends something like `abcd`, it should not be considered as true or false for a checkbox field but instead it should be considered as invalid.\r\n\r\nTo enable it, you need to use the `api` type:\r\n\r\n``` php\r\n$builder->add('enabled', CheckboxType::class, [\r\n    'type' => 'api',\r\n    'true_values'  => ['1', 'true', 'yes', 'on'],\r\n    'false_values' => ['0', 'false', 'no', 'off', '', null],\r\n]);\r\n```\r\n\r\nEnabling it will automatically convert the defined `true_values` to `true` and the `false_values` to `false`. Anything else will trigger a transformation failed exception and mark the form as invalid. The true/false values are optional, I add them in the example in order to more easily explain how does it work. The values used here are the default ones except for the type one.\r\n\r\nIf you look it closely you will notice the values looks strange. We don't allow the `true`/`false` values or the `1`/`0` values but instead we allow there string representations. This is because the form component automatically converts scalar value to string and false to null (See [here](https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Form/Form.php#L525-L529)). So, the values provided must reflect this form behavior.\r\n\r\nFor the list of supported submitted boolean values, you can take a look to the PHPUnit data provider in the extension tests.\r\n\r\nWDYT?","created_at":"2016-01-14T20:34:42Z","updated_at":"2016-01-15T19:10:42Z","closed_at":null,"merged_at":null,"merge_commit_sha":"582b42d4885f72f73b84f31138dc166e7a02e44e","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/pulls/1312/commits","review_comments_url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/pulls/1312/comments","review_comment_url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/pulls/comments{/number}","comments_url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/issues/1312/comments","statuses_url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/statuses/468315562b28efb80d34c232624f36d9082af66c","head":{"label":"egeloen:boolean-extension","ref":"boolean-extension","sha":"468315562b28efb80d34c232624f36d9082af66c","user":{"login":"egeloen","id":737992,"avatar_url":"https://avatars.githubusercontent.com/u/737992?v=3","gravatar_id":"","url":"https://api.github.com/users/egeloen","html_url":"https://github.com/egeloen","followers_url":"https://api.github.com/users/egeloen/followers","following_url":"https://api.github.com/users/egeloen/following{/other_user}","gists_url":"https://api.github.com/users/egeloen/gists{/gist_id}","starred_url":"https://api.github.com/users/egeloen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/egeloen/subscriptions","organizations_url":"https://api.github.com/users/egeloen/orgs","repos_url":"https://api.github.com/users/egeloen/repos","events_url":"https://api.github.com/users/egeloen/events{/privacy}","received_events_url":"https://api.github.com/users/egeloen/received_events","type":"User","site_admin":false},"repo":{"id":49593343,"name":"FOSRestBundle","full_name":"egeloen/FOSRestBundle","owner":{"login":"egeloen","id":737992,"avatar_url":"https://avatars.githubusercontent.com/u/737992?v=3","gravatar_id":"","url":"https://api.github.com/users/egeloen","html_url":"https://github.com/egeloen","followers_url":"https://api.github.com/users/egeloen/followers","following_url":"https://api.github.com/users/egeloen/following{/other_user}","gists_url":"https://api.github.com/users/egeloen/gists{/gist_id}","starred_url":"https://api.github.com/users/egeloen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/egeloen/subscriptions","organizations_url":"https://api.github.com/users/egeloen/orgs","repos_url":"https://api.github.com/users/egeloen/repos","events_url":"https://api.github.com/users/egeloen/events{/privacy}","received_events_url":"https://api.github.com/users/egeloen/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/egeloen/FOSRestBundle","description":"This Bundle provides various tools to rapidly develop RESTful API's with Symfony2","fork":true,"url":"https://api.github.com/repos/egeloen/FOSRestBundle","forks_url":"https://api.github.com/repos/egeloen/FOSRestBundle/forks","keys_url":"https://api.github.com/repos/egeloen/FOSRestBundle/keys{/key_id}","collaborators_url":"https://api.github.com/repos/egeloen/FOSRestBundle/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/egeloen/FOSRestBundle/teams","hooks_url":"https://api.github.com/repos/egeloen/FOSRestBundle/hooks","issue_events_url":"https://api.github.com/repos/egeloen/FOSRestBundle/issues/events{/number}","events_url":"https://api.github.com/repos/egeloen/FOSRestBundle/events","assignees_url":"https://api.github.com/repos/egeloen/FOSRestBundle/assignees{/user}","branches_url":"https://api.github.com/repos/egeloen/FOSRestBundle/branches{/branch}","tags_url":"https://api.github.com/repos/egeloen/FOSRestBundle/tags","blobs_url":"https://api.github.com/repos/egeloen/FOSRestBundle/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/egeloen/FOSRestBundle/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/egeloen/FOSRestBundle/git/refs{/sha}","trees_url":"https://api.github.com/repos/egeloen/FOSRestBundle/git/trees{/sha}","statuses_url":"https://api.github.com/repos/egeloen/FOSRestBundle/statuses/{sha}","languages_url":"https://api.github.com/repos/egeloen/FOSRestBundle/languages","stargazers_url":"https://api.github.com/repos/egeloen/FOSRestBundle/stargazers","contributors_url":"https://api.github.com/repos/egeloen/FOSRestBundle/contributors","subscribers_url":"https://api.github.com/repos/egeloen/FOSRestBundle/subscribers","subscription_url":"https://api.github.com/repos/egeloen/FOSRestBundle/subscription","commits_url":"https://api.github.com/repos/egeloen/FOSRestBundle/commits{/sha}","git_commits_url":"https://api.github.com/repos/egeloen/FOSRestBundle/git/commits{/sha}","comments_url":"https://api.github.com/repos/egeloen/FOSRestBundle/comments{/number}","issue_comment_url":"https://api.github.com/repos/egeloen/FOSRestBundle/issues/comments{/number}","contents_url":"https://api.github.com/repos/egeloen/FOSRestBundle/contents/{+path}","compare_url":"https://api.github.com/repos/egeloen/FOSRestBundle/compare/{base}...{head}","merges_url":"https://api.github.com/repos/egeloen/FOSRestBundle/merges","archive_url":"https://api.github.com/repos/egeloen/FOSRestBundle/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/egeloen/FOSRestBundle/downloads","issues_url":"https://api.github.com/repos/egeloen/FOSRestBundle/issues{/number}","pulls_url":"https://api.github.com/repos/egeloen/FOSRestBundle/pulls{/number}","milestones_url":"https://api.github.com/repos/egeloen/FOSRestBundle/milestones{/number}","notifications_url":"https://api.github.com/repos/egeloen/FOSRestBundle/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/egeloen/FOSRestBundle/labels{/name}","releases_url":"https://api.github.com/repos/egeloen/FOSRestBundle/releases{/id}","created_at":"2016-01-13T18:31:07Z","updated_at":"2016-01-13T18:31:10Z","pushed_at":"2016-01-15T19:05:50Z","git_url":"git://github.com/egeloen/FOSRestBundle.git","ssh_url":"git@github.com:egeloen/FOSRestBundle.git","clone_url":"https://github.com/egeloen/FOSRestBundle.git","svn_url":"https://github.com/egeloen/FOSRestBundle","homepage":"http://friendsofsymfony.github.com/","size":3423,"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:1.8","ref":"1.8","sha":"b8476e0a8f11f3d67f6bd9a830f18a04e5d202a5","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":1509011,"name":"FOSRestBundle","full_name":"FriendsOfSymfony/FOSRestBundle","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/FOSRestBundle","description":"This Bundle provides various tools to rapidly develop RESTful API's with Symfony2","fork":false,"url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle","forks_url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/forks","keys_url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/keys{/key_id}","collaborators_url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/teams","hooks_url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/hooks","issue_events_url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/issues/events{/number}","events_url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/events","assignees_url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/assignees{/user}","branches_url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/branches{/branch}","tags_url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/tags","blobs_url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/git/refs{/sha}","trees_url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/git/trees{/sha}","statuses_url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/statuses/{sha}","languages_url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/languages","stargazers_url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/stargazers","contributors_url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/contributors","subscribers_url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/subscribers","subscription_url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/subscription","commits_url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/commits{/sha}","git_commits_url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/git/commits{/sha}","comments_url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/comments{/number}","issue_comment_url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/issues/comments{/number}","contents_url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/contents/{+path}","compare_url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/compare/{base}...{head}","merges_url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/merges","archive_url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/downloads","issues_url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/issues{/number}","pulls_url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/pulls{/number}","milestones_url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/milestones{/number}","notifications_url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/labels{/name}","releases_url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/releases{/id}","created_at":"2011-03-21T23:14:13Z","updated_at":"2016-01-13T17:52:38Z","pushed_at":"2016-01-15T19:05:50Z","git_url":"git://github.com/FriendsOfSymfony/FOSRestBundle.git","ssh_url":"git@github.com:FriendsOfSymfony/FOSRestBundle.git","clone_url":"https://github.com/FriendsOfSymfony/FOSRestBundle.git","svn_url":"https://github.com/FriendsOfSymfony/FOSRestBundle","homepage":"http://friendsofsymfony.github.com/","size":4524,"stargazers_count":1261,"watchers_count":1261,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":505,"mirror_url":null,"open_issues_count":76,"forks":505,"open_issues":76,"watchers":1261,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/pulls/1312"},"html":{"href":"https://github.com/FriendsOfSymfony/FOSRestBundle/pull/1312"},"issue":{"href":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/issues/1312"},"comments":{"href":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/issues/1312/comments"},"review_comments":{"href":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/pulls/1312/comments"},"review_comment":{"href":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/pulls/1312/commits"},"statuses":{"href":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/statuses/468315562b28efb80d34c232624f36d9082af66c"}}}}