{"action":"created","comment":{"url":"https://api.github.com/repos/symfony/symfony/pulls/comments/23767547","id":23767547,"diff_hunk":"@@ -0,0 +1,129 @@\n+<?php\n+\n+/*\n+ * This file is part of the Symfony package.\n+ *\n+ * (c) Fabien Potencier <fabien@symfony.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 Symfony\\Component\\Form\\Extension\\Core\\Type;\n+\n+use Symfony\\Component\\Form\\AbstractType;\n+use Symfony\\Component\\OptionsResolver\\OptionsResolverInterface;\n+use Symfony\\Component\\OptionsResolver\\Options;\n+\n+class DayOfWeekType extends AbstractType\n+{\n+    /**\n+     * {@inheritdoc}\n+     */\n+    public function setDefaultOptions(OptionsResolverInterface $resolver)\n+    {\n+        //  IntlCalendar::DOW_* constants\n+        $daysOfWeek = array(\n+            \\IntlCalendar::DOW_SUNDAY    => 'sunday',\n+            \\IntlCalendar::DOW_MONDAY    => 'monday',\n+            \\IntlCalendar::DOW_TUESDAY   => 'tuesday',\n+            \\IntlCalendar::DOW_WEDNESDAY => 'wednesday',\n+            \\IntlCalendar::DOW_THURSDAY  => 'thursday',\n+            \\IntlCalendar::DOW_FRIDAY    => 'friday',\n+            \\IntlCalendar::DOW_SATURDAY  => 'saturday',\n+        );\n+\n+        /**\n+         * Goes through all daysOfWeek once, starting at $firstDayOfWeek\n+         *\n+         * @param int $firstDayOfWeek\n+         * @return array\n+         */\n+        $getOrderedDaysOfWeek = function ($firstDayOfWeek, $valueFormat) use (&$daysOfWeek) {\n+            $days = array();\n+\n+            // goes through all items once, starting at $firstDayOfWeek\n+            for ($dayOfWeek = $firstDayOfWeek - 1; $dayOfWeek < ($firstDayOfWeek + 6); $dayOfWeek++) {\n+                $slug = $daysOfWeek[($dayOfWeek % 7) + 1];\n+                $value = $valueFormat === 'slug' ?  $slug : $dayOfWeek;\n+                $days[$value] = $slug;\n+            }\n+\n+            return $days;\n+        };\n+\n+        /**\n+         * Replace values with the formatted day of the week.\n+         * Uses strtotime('monday')\n+         *\n+         * @param IntlDateFormatter $formatter\n+         * @param array $days\n+         * @return array\n+         */\n+        $getDayNames = function (\\IntlDateFormatter $formatter, array $days) {\n+            $names = null;\n+            $timestamps = array_map('strtotime', array_values($days));\n+            $names = array_map(array($formatter, 'format'), $timestamps);\n+\n+            return array_combine(array_keys($days), $names);\n+        };\n+\n+        $resolver->setDefault('timezone', null);\n+        $resolver->setAllowedTypes('timezone', array('DateTimeZone', 'null'));\n+\n+        $resolver->setDefault('locale', \\Locale::getDefault());\n+        $locales = \\IntlCalendar::getAvailableLocales();\n+        $locales[] = null; // allow null, system default\n+        $resolver->setAllowedValues('locale', $locales);\n+\n+        $resolver->setDefault('calendar', function (Options $options) {\n+            return \\IntlCalendar::createInstance($options['timezone'], $options['locale']);\n+        });\n+        $resolver->setAllowedTypes('calendar', 'IntlCalendar');\n+\n+        $resolver->setDefault('firstdow', function (Options $options) {\n+            return $options['calendar']->getFirstDayOfWeek();\n+        });\n+        $resolver->setAllowedValues('firstdow', array_keys($daysOfWeek));\n+\n+        $resolver->setDefault('label_format', 'eeee');\n+        $resolver->setAllowedTypes('label_format', 'string');\n+\n+        $resolver->setDefault('value_format', 'index');\n+        $resolver->setAllowedValues('value_format', array('index', 'slug'));\n+\n+        $resolver->setDefault('formatter', function (Options $options) {","path":"src/Symfony/Component/Form/Extension/Core/Type/DayOfWeekType.php","position":95,"original_position":95,"commit_id":"1fe77a3b5d12c0fa29e4d39069f82c9d23158232","original_commit_id":"1fe77a3b5d12c0fa29e4d39069f82c9d23158232","user":{"login":"zebba","id":1733631,"avatar_url":"https://avatars.githubusercontent.com/u/1733631?v=3","gravatar_id":"","url":"https://api.github.com/users/zebba","html_url":"https://github.com/zebba","followers_url":"https://api.github.com/users/zebba/followers","following_url":"https://api.github.com/users/zebba/following{/other_user}","gists_url":"https://api.github.com/users/zebba/gists{/gist_id}","starred_url":"https://api.github.com/users/zebba/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zebba/subscriptions","organizations_url":"https://api.github.com/users/zebba/orgs","repos_url":"https://api.github.com/users/zebba/repos","events_url":"https://api.github.com/users/zebba/events{/privacy}","received_events_url":"https://api.github.com/users/zebba/received_events","type":"User","site_admin":false},"body":"See above.","created_at":"2015-01-29T13:42:33Z","updated_at":"2015-01-29T13:42:33Z","html_url":"https://github.com/symfony/symfony/pull/13471#discussion_r23767547","pull_request_url":"https://api.github.com/repos/symfony/symfony/pulls/13471","_links":{"self":{"href":"https://api.github.com/repos/symfony/symfony/pulls/comments/23767547"},"html":{"href":"https://github.com/symfony/symfony/pull/13471#discussion_r23767547"},"pull_request":{"href":"https://api.github.com/repos/symfony/symfony/pulls/13471"}}},"pull_request":{"url":"https://api.github.com/repos/symfony/symfony/pulls/13471","id":27716144,"html_url":"https://github.com/symfony/symfony/pull/13471","diff_url":"https://github.com/symfony/symfony/pull/13471.diff","patch_url":"https://github.com/symfony/symfony/pull/13471.patch","issue_url":"https://api.github.com/repos/symfony/symfony/issues/13471","number":13471,"state":"open","locked":false,"title":"[Form] Added DayOfWeek type","user":{"login":"lavoiesl","id":1216046,"avatar_url":"https://avatars.githubusercontent.com/u/1216046?v=3","gravatar_id":"","url":"https://api.github.com/users/lavoiesl","html_url":"https://github.com/lavoiesl","followers_url":"https://api.github.com/users/lavoiesl/followers","following_url":"https://api.github.com/users/lavoiesl/following{/other_user}","gists_url":"https://api.github.com/users/lavoiesl/gists{/gist_id}","starred_url":"https://api.github.com/users/lavoiesl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lavoiesl/subscriptions","organizations_url":"https://api.github.com/users/lavoiesl/orgs","repos_url":"https://api.github.com/users/lavoiesl/repos","events_url":"https://api.github.com/users/lavoiesl/events{/privacy}","received_events_url":"https://api.github.com/users/lavoiesl/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?   | not written yet\r\n| Fixed tickets | -\r\n| License       | MIT\r\n| Doc PR        | not written yet\r\n\r\n- [ ] Gather comments on how to address this.\r\n- [ ] Write tests.\r\n- [ ] Write documentation.\r\n- [x] Normalize and validate options in the OptionResolver.\r\n\r\nThis PR is a proof of concept and I would like to gather some comments before finishing the work.\r\n\r\nAs of now, it uses `IntlDateFormatter` to figure out which is the first day of the week and the generated choices look like this:\r\n\r\n```php\r\n<?php\r\n// fr\r\narray(\r\n    1 => 'dimanche',\r\n    2 => 'lundi',\r\n    3 => 'mardi',\r\n    4 => 'mercredi',\r\n    5 => 'jeudi',\r\n    6 => 'vendredi',\r\n    7 => 'samedi',\r\n);\r\n\r\n// en\r\narray(\r\n    2 => 'Monday',\r\n    3 => 'Tuesday',\r\n    4 => 'Wednesday',\r\n    5 => 'Thursday',\r\n    6 => 'Friday',\r\n    7 => 'Saturday',\r\n    1 => 'Sunday',\r\n);\r\n?>\r\n```\r\n\r\nThe options are:\r\n\r\n * `label_format`: format passed to `IntlDateFormatter::format`. Default `eeee` (full day name)\r\n * `value_format`: Either `index`: integer indices (`IntlCalendar::DOW_*` constants) or `slug`: english string representation (e.g. `monday`). Default `index`.\r\n * `timezone`: Used to create the calendar to figure out the first day of the week. Defaults to system timezone.\r\n * `locale`: Used to create the calendar to figure out the first day of the week and translate the day names. Defaults to `Locale::getDefault`.\r\n * `calendar`: `IntlCalendar` object. Infereed from `timezone` and `locale`.\r\n * `firstdow`: One of `IntlCalendar::DOW_*` constants (integer). Inferred from `calendar`.\r\n * `choices`: You could always override the whole choices, but that would defeat the purpose.\r\n\r\n***\r\n\r\nSo, anyone interested ?\r\n","created_at":"2015-01-20T21:56:45Z","updated_at":"2015-01-29T13:42:33Z","closed_at":null,"merged_at":null,"merge_commit_sha":"660575c95a063f695bad26b34336a8a4cf384684","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/symfony/symfony/pulls/13471/commits","review_comments_url":"https://api.github.com/repos/symfony/symfony/pulls/13471/comments","review_comment_url":"https://api.github.com/repos/symfony/symfony/pulls/comments/{number}","comments_url":"https://api.github.com/repos/symfony/symfony/issues/13471/comments","statuses_url":"https://api.github.com/repos/symfony/symfony/statuses/1fe77a3b5d12c0fa29e4d39069f82c9d23158232","head":{"label":"lavoiesl:form-type-dayofweek","ref":"form-type-dayofweek","sha":"1fe77a3b5d12c0fa29e4d39069f82c9d23158232","user":{"login":"lavoiesl","id":1216046,"avatar_url":"https://avatars.githubusercontent.com/u/1216046?v=3","gravatar_id":"","url":"https://api.github.com/users/lavoiesl","html_url":"https://github.com/lavoiesl","followers_url":"https://api.github.com/users/lavoiesl/followers","following_url":"https://api.github.com/users/lavoiesl/following{/other_user}","gists_url":"https://api.github.com/users/lavoiesl/gists{/gist_id}","starred_url":"https://api.github.com/users/lavoiesl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lavoiesl/subscriptions","organizations_url":"https://api.github.com/users/lavoiesl/orgs","repos_url":"https://api.github.com/users/lavoiesl/repos","events_url":"https://api.github.com/users/lavoiesl/events{/privacy}","received_events_url":"https://api.github.com/users/lavoiesl/received_events","type":"User","site_admin":false},"repo":{"id":4593430,"name":"symfony","full_name":"lavoiesl/symfony","owner":{"login":"lavoiesl","id":1216046,"avatar_url":"https://avatars.githubusercontent.com/u/1216046?v=3","gravatar_id":"","url":"https://api.github.com/users/lavoiesl","html_url":"https://github.com/lavoiesl","followers_url":"https://api.github.com/users/lavoiesl/followers","following_url":"https://api.github.com/users/lavoiesl/following{/other_user}","gists_url":"https://api.github.com/users/lavoiesl/gists{/gist_id}","starred_url":"https://api.github.com/users/lavoiesl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lavoiesl/subscriptions","organizations_url":"https://api.github.com/users/lavoiesl/orgs","repos_url":"https://api.github.com/users/lavoiesl/repos","events_url":"https://api.github.com/users/lavoiesl/events{/privacy}","received_events_url":"https://api.github.com/users/lavoiesl/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/lavoiesl/symfony","description":"The Symfony2 PHP framework","fork":true,"url":"https://api.github.com/repos/lavoiesl/symfony","forks_url":"https://api.github.com/repos/lavoiesl/symfony/forks","keys_url":"https://api.github.com/repos/lavoiesl/symfony/keys{/key_id}","collaborators_url":"https://api.github.com/repos/lavoiesl/symfony/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/lavoiesl/symfony/teams","hooks_url":"https://api.github.com/repos/lavoiesl/symfony/hooks","issue_events_url":"https://api.github.com/repos/lavoiesl/symfony/issues/events{/number}","events_url":"https://api.github.com/repos/lavoiesl/symfony/events","assignees_url":"https://api.github.com/repos/lavoiesl/symfony/assignees{/user}","branches_url":"https://api.github.com/repos/lavoiesl/symfony/branches{/branch}","tags_url":"https://api.github.com/repos/lavoiesl/symfony/tags","blobs_url":"https://api.github.com/repos/lavoiesl/symfony/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/lavoiesl/symfony/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/lavoiesl/symfony/git/refs{/sha}","trees_url":"https://api.github.com/repos/lavoiesl/symfony/git/trees{/sha}","statuses_url":"https://api.github.com/repos/lavoiesl/symfony/statuses/{sha}","languages_url":"https://api.github.com/repos/lavoiesl/symfony/languages","stargazers_url":"https://api.github.com/repos/lavoiesl/symfony/stargazers","contributors_url":"https://api.github.com/repos/lavoiesl/symfony/contributors","subscribers_url":"https://api.github.com/repos/lavoiesl/symfony/subscribers","subscription_url":"https://api.github.com/repos/lavoiesl/symfony/subscription","commits_url":"https://api.github.com/repos/lavoiesl/symfony/commits{/sha}","git_commits_url":"https://api.github.com/repos/lavoiesl/symfony/git/commits{/sha}","comments_url":"https://api.github.com/repos/lavoiesl/symfony/comments{/number}","issue_comment_url":"https://api.github.com/repos/lavoiesl/symfony/issues/comments/{number}","contents_url":"https://api.github.com/repos/lavoiesl/symfony/contents/{+path}","compare_url":"https://api.github.com/repos/lavoiesl/symfony/compare/{base}...{head}","merges_url":"https://api.github.com/repos/lavoiesl/symfony/merges","archive_url":"https://api.github.com/repos/lavoiesl/symfony/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/lavoiesl/symfony/downloads","issues_url":"https://api.github.com/repos/lavoiesl/symfony/issues{/number}","pulls_url":"https://api.github.com/repos/lavoiesl/symfony/pulls{/number}","milestones_url":"https://api.github.com/repos/lavoiesl/symfony/milestones{/number}","notifications_url":"https://api.github.com/repos/lavoiesl/symfony/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/lavoiesl/symfony/labels{/name}","releases_url":"https://api.github.com/repos/lavoiesl/symfony/releases{/id}","created_at":"2012-06-08T04:03:48Z","updated_at":"2014-06-10T17:36:37Z","pushed_at":"2015-01-28T20:36:00Z","git_url":"git://github.com/lavoiesl/symfony.git","ssh_url":"git@github.com:lavoiesl/symfony.git","clone_url":"https://github.com/lavoiesl/symfony.git","svn_url":"https://github.com/lavoiesl/symfony","homepage":"symfony.com","size":51124,"stargazers_count":1,"watchers_count":1,"language":"PHP","has_issues":false,"has_downloads":false,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":1,"default_branch":"master"}},"base":{"label":"symfony:2.7","ref":"2.7","sha":"28931800a06fcb5cbf109e28559ba6983682a5ee","user":{"login":"symfony","id":143937,"avatar_url":"https://avatars.githubusercontent.com/u/143937?v=3","gravatar_id":"","url":"https://api.github.com/users/symfony","html_url":"https://github.com/symfony","followers_url":"https://api.github.com/users/symfony/followers","following_url":"https://api.github.com/users/symfony/following{/other_user}","gists_url":"https://api.github.com/users/symfony/gists{/gist_id}","starred_url":"https://api.github.com/users/symfony/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/symfony/subscriptions","organizations_url":"https://api.github.com/users/symfony/orgs","repos_url":"https://api.github.com/users/symfony/repos","events_url":"https://api.github.com/users/symfony/events{/privacy}","received_events_url":"https://api.github.com/users/symfony/received_events","type":"Organization","site_admin":false},"repo":{"id":458058,"name":"symfony","full_name":"symfony/symfony","owner":{"login":"symfony","id":143937,"avatar_url":"https://avatars.githubusercontent.com/u/143937?v=3","gravatar_id":"","url":"https://api.github.com/users/symfony","html_url":"https://github.com/symfony","followers_url":"https://api.github.com/users/symfony/followers","following_url":"https://api.github.com/users/symfony/following{/other_user}","gists_url":"https://api.github.com/users/symfony/gists{/gist_id}","starred_url":"https://api.github.com/users/symfony/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/symfony/subscriptions","organizations_url":"https://api.github.com/users/symfony/orgs","repos_url":"https://api.github.com/users/symfony/repos","events_url":"https://api.github.com/users/symfony/events{/privacy}","received_events_url":"https://api.github.com/users/symfony/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/symfony/symfony","description":"The Symfony PHP framework","fork":false,"url":"https://api.github.com/repos/symfony/symfony","forks_url":"https://api.github.com/repos/symfony/symfony/forks","keys_url":"https://api.github.com/repos/symfony/symfony/keys{/key_id}","collaborators_url":"https://api.github.com/repos/symfony/symfony/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/symfony/symfony/teams","hooks_url":"https://api.github.com/repos/symfony/symfony/hooks","issue_events_url":"https://api.github.com/repos/symfony/symfony/issues/events{/number}","events_url":"https://api.github.com/repos/symfony/symfony/events","assignees_url":"https://api.github.com/repos/symfony/symfony/assignees{/user}","branches_url":"https://api.github.com/repos/symfony/symfony/branches{/branch}","tags_url":"https://api.github.com/repos/symfony/symfony/tags","blobs_url":"https://api.github.com/repos/symfony/symfony/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/symfony/symfony/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/symfony/symfony/git/refs{/sha}","trees_url":"https://api.github.com/repos/symfony/symfony/git/trees{/sha}","statuses_url":"https://api.github.com/repos/symfony/symfony/statuses/{sha}","languages_url":"https://api.github.com/repos/symfony/symfony/languages","stargazers_url":"https://api.github.com/repos/symfony/symfony/stargazers","contributors_url":"https://api.github.com/repos/symfony/symfony/contributors","subscribers_url":"https://api.github.com/repos/symfony/symfony/subscribers","subscription_url":"https://api.github.com/repos/symfony/symfony/subscription","commits_url":"https://api.github.com/repos/symfony/symfony/commits{/sha}","git_commits_url":"https://api.github.com/repos/symfony/symfony/git/commits{/sha}","comments_url":"https://api.github.com/repos/symfony/symfony/comments{/number}","issue_comment_url":"https://api.github.com/repos/symfony/symfony/issues/comments/{number}","contents_url":"https://api.github.com/repos/symfony/symfony/contents/{+path}","compare_url":"https://api.github.com/repos/symfony/symfony/compare/{base}...{head}","merges_url":"https://api.github.com/repos/symfony/symfony/merges","archive_url":"https://api.github.com/repos/symfony/symfony/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/symfony/symfony/downloads","issues_url":"https://api.github.com/repos/symfony/symfony/issues{/number}","pulls_url":"https://api.github.com/repos/symfony/symfony/pulls{/number}","milestones_url":"https://api.github.com/repos/symfony/symfony/milestones{/number}","notifications_url":"https://api.github.com/repos/symfony/symfony/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/symfony/symfony/labels{/name}","releases_url":"https://api.github.com/repos/symfony/symfony/releases{/id}","created_at":"2010-01-04T14:21:21Z","updated_at":"2015-01-29T09:03:04Z","pushed_at":"2015-01-27T10:45:36Z","git_url":"git://github.com/symfony/symfony.git","ssh_url":"git@github.com:symfony/symfony.git","clone_url":"https://github.com/symfony/symfony.git","svn_url":"https://github.com/symfony/symfony","homepage":"symfony.com","size":189224,"stargazers_count":9590,"watchers_count":9590,"language":"PHP","has_issues":true,"has_downloads":false,"has_wiki":false,"has_pages":false,"forks_count":3741,"mirror_url":null,"open_issues_count":788,"forks":3741,"open_issues":788,"watchers":9590,"default_branch":"2.7"}},"_links":{"self":{"href":"https://api.github.com/repos/symfony/symfony/pulls/13471"},"html":{"href":"https://github.com/symfony/symfony/pull/13471"},"issue":{"href":"https://api.github.com/repos/symfony/symfony/issues/13471"},"comments":{"href":"https://api.github.com/repos/symfony/symfony/issues/13471/comments"},"review_comments":{"href":"https://api.github.com/repos/symfony/symfony/pulls/13471/comments"},"review_comment":{"href":"https://api.github.com/repos/symfony/symfony/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/symfony/symfony/pulls/13471/commits"},"statuses":{"href":"https://api.github.com/repos/symfony/symfony/statuses/1fe77a3b5d12c0fa29e4d39069f82c9d23158232"}}}}