8000 Update src/Symfony/Component/Form/Extension/Core/Type/MoneyType.php · gedrox/symfony@01ae07e · GitHub
[go: up one dir, main page]

Skip to content

Commit 01ae07e

Browse files
committed
Update src/Symfony/Component/Form/Extension/Core/Type/MoneyType.php
Money type pattern local cache was not working.
1 parent f4570d5 commit 01ae07e

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/Symfony/Component/Form/Extension/Core/Type/MoneyType.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,15 @@ private static function getPattern($currency)
8686
if (!$currency) {
8787
return '{{ widget }}';
8888
}
89+
90+
$locale = \Locale::getDefault();
8991

90-
if (!isset(self::$patterns[\Locale::getDefault()])) {
91-
self::$patterns[\Locale::getDefault()] = array();
92+
if (!isset(self::$patterns[$locale])) {
93+
self::$patterns[$locale] = array();
9294
}
9395

94-
if (!isset(self::$patterns[\Locale::getDefault()][$currency])) {
95-
$format = new \NumberFormatter(\Locale::getDefault(), \NumberFormatter::CURRENCY);
96+
if (!isset(self::$patterns[$locale][$currency])) {
97+
$format = new \NumberFormatter($locale, \NumberFormatter::CURRENCY);
9698
$pattern = $format->formatCurrency('123', $currency);
9799

98100
// the spacings between currency symbol and number are ignored, because
@@ -104,14 +106,14 @@ private static function getPattern($currency)
104106
preg_match('/^([^\s\xc2\xa0]*)[\s\xc2\xa0]*123(?:[,.]0+)?[\s\xc2\xa0]*([^\s\xc2\xa0]*)$/u', $pattern, $matches);
105107

106108
if (!empty($matches[1])) {
107-
self::$patterns[\Locale::getDefault()] = $matches[1].' {{ widget }}';
109+
self::$patterns[$locale][$currency] = $matches[1].' {{ widget }}';
108110
} elseif (!empty($matches[2])) {
109-
self::$patterns[\Locale::getDefault()] = '{{ widget }} '.$matches[2];
111+
self::$patterns[$locale][$currency] = '{{ widget }} '.$matches[2];
110112
} else {
111-
self::$patterns[\Locale::getDefault()] = '{{ widget }}';
113+
self::$patterns[$locale][$currency] = '{{ widget }}';
112114
}
113115
}
114116

115-
return self::$patterns[\Locale::getDefault()];
117+
return self::$patterns[$locale][$currency];
116118
}
117119
}

0 commit comments

Comments
 (0)
0