File tree 4 files changed +116
-4
lines changed
src/Symfony/Component/Form/Extension/Core/Type
4 files changed +116
-4
lines changed Original file line number Diff line number Diff line change 17
17
18
18
class CountryType extends AbstractType
19
19
{
20
+ /**
21
+ * Stores the available country choices.
22
+ *
23
+ * @var array
24
+ */
25
+ private static $ countries ;
26
+
20
27
/**
21
28
* {@inheritdoc}
22
29
*/
23
30
public function configureOptions (OptionsResolver $ resolver )
24
31
{
25
32
$ resolver ->setDefaults (array (
26
- 'choices ' => array_flip (Intl:: getRegionBundle ()-> getCountryNames () ),
33
+ 'choices ' => self :: getCountries ( ),
27
34
'choice_translation_domain ' => false ,
28
35
));
29
36
}
@@ -43,4 +50,25 @@ public function getBlockPrefix()
43
50
{
44
51
return 'country ' ;
45
52
}
53
+
54
+ /**
55
+ * Returns the country choices.
56
+ *
57
+ * The choices are generated from the Intl component
58
+ * {@link \Symfony\Component\Intl\Intl::getRegionBundle()}.
59
+ *
60
+ * They are cached during a single request, so multiple
61
+ * country fields on the same page don't lead to
62
+ * unnecessary overhead.
63
+ *
64
+ * @return array The country choices
65
+ */
66
+ private static function getCountries ()
67
+ {
68
+ if (null === self ::$ countries ) {
69
+ self ::$ countries = array_flip (Intl::getRegionBundle ()->getCountryNames ());
70
+ }
71
+
72
+ return self ::$ countries ;
73
+ }
46
74
}
Original file line number Diff line number Diff line change 17
17
18
18
class CurrencyType extends AbstractType
19
19
{
20
+ /**
21
+ * Stores the available currency choices.
22
+ *
23
+ * @var array
24
+ */
25
+ private static $ currencies ;
26
+
20
27
/**
21
28
* {@inheritdoc}
22
29
*/
23
30
public function configureOptions (OptionsResolver $ resolver )
24
31
{
25
32
$ resolver ->setDefaults (array (
26
- 'choices ' => array_flip (Intl:: getCurrencyBundle ()-> getCurrencyNames () ),
33
+ 'choices ' => self :: getCurrencies ( ),
27
34
'choice_translation_domain ' => false ,
28
35
));
29
36
}
@@ -43,4 +50,25 @@ public function getBlockPrefix()
43
50
{
44
51
return 'currency ' ;
45
52
}
53
+
54
+ /**
55
+ * Returns the currency choices.
56
+ *
57
+ * The choices are generated from the Intl component
58
+ * {@link \Symfony\Component\Intl\Intl::getCurrencyBundle()}.
59
+ *
60
+ * They are cached during a single request, so multiple
61
+ * currency fields on the same page don't lead to
62
+ * unnecessary overhead.
63
+ *
64
+ * @return array The currency choices
65
+ */
66
+ private static function getCurrencies ()
67
+ {
68
+ if (null === self ::$ currencies ) {
69
+ self ::$ currencies = array_flip (Intl::getCurrencyBundle ()->getCurrencyNames ());
70
+ }
71
+
72
+ return self ::$ currencies ;
73
+ }
46
74
}
Original file line number Diff line number Diff line change 17
17
18
18
class LanguageType extends AbstractType
19
19
{
20
+ /**
21
+ * Stores the available language choices.
22
+ *
23
+ * @var array
24
+ */
25
+ private static $ languages ;
26
+
20
27
/**
21
28
* {@inheritdoc}
22
29
*/
23
30
public function configureOptions (OptionsResolver $ resolver )
24
31
{
25
32
$ resolver ->setDefaults (array (
26
- 'choices ' => array_flip (Intl:: getLanguageBundle ()-> getLanguageNames () ),
33
+ 'choices ' => self :: getLanguages ( ),
27
34
'choice_translation_domain ' => false ,
28
35
));
29
36
}
@@ -43,4 +50,25 @@ public function getBlockPrefix()
43
50
{
44
51
return 'language ' ;
45
52
}
53
+
54
+ /**
55
+ * Returns the language choices.
56
+ *
57
+ * The choices are generated from the Intl component
58
+ * {@link \Symfony\Component\Intl\Intl::getLanguageBundle()}.
59
+ *
60
+ * They are cached during a single request, so multiple
61
+ * language fields on the same page don't lead to
62
+ * unnecessary overhead.
63
+ *
64
+ * @return array The language choices
65
+ */
66
+ private static function getLanguages ()
67
+ {
68
+ if (null === self ::$ languages ) {
69
+ self ::$ languages = array_flip (Intl::getLanguageBundle ()->getLanguageNames ());
70
+ }
71
+
72
+ return self ::$ languages ;
73
+ }
46
74
}
Original file line number Diff line number Diff line change 17
17
18
18
class LocaleType extends AbstractType
19
19
{
20
+ /**
21
+ * Stores the available locale choices.
22
+ *
23
+ * @var array
24
+ */
25
+ private static $ locales ;
26
+
20
27
/**
21
28
* {@inheritdoc}
22
29
*/
23
30
public function configureOptions (OptionsResolver $ resolver )
24
31
{
25
32
$ resolver ->setDefaults (array (
26
- 'choices ' => array_flip (Intl:: getLocaleBundle ()-> getLocaleNames () ),
33
+ 'choices ' => self :: getLocales ( ),
27
34
'choice_translation_domain ' => false ,
28
35
));
29
36
}
@@ -43,4 +50,25 @@ public function getBlockPrefix()
43
50
{
44
51
return 'locale ' ;
45
52
}
53
+
54
+ /**
55
+ * Returns the locale choices.
56
+ *
57
+ * The choices are generated from the Intl component
58
+ * {@link \Symfony\Component\Intl\Intl::getLocaleBundle()}.
59
+ *
60
+ * They are cached during a single request, so multiple
61
+ * locale fields on the same page don't lead to
62
+ * unnecessary overhead.
63
+ *
64
+ * @return array The locale choices
65
+ */
66
+ private static function getLocales ()
67
+ {
68
+ if (null === self ::$ locales ) {
69
+ self ::$ locales = array_flip (Intl::getLocaleBundle ()->getLocaleNames ());
70
+ }
71
+
72
+ return self ::$ locales ;
73
+ }
46
74
}
You can’t perform that action at this time.
0 commit comments