From 474a67da99d3267de079127b49944170673712d8 Mon Sep 17 00:00:00 2001 From: Anton Date: Thu, 16 Jun 2022 12:32:08 +0300 Subject: [PATCH] Fix caching in `Formatter::getUnitMessage()` (#19445) * Fix caching in `Formatter::getUnitMessage()` * Update FormatterTest.php * Update CHANGELOG.md --- framework/CHANGELOG.md | 1 + framework/i18n/Formatter.php | 6 +++--- tests/framework/i18n/FormatterTest.php | 5 +++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index e3a9eb30641..bb64e7b2f3d 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -35,6 +35,7 @@ Yii Framework 2 Change Log - Enh #19416: Update and improve configurations for `yii\console\controllers\MessageController` (WinterSilence) - Bug #19403: Fix types in `yii\web\SessionIterator` (WinterSilence) - Enh #19420: Update list of JS callbacks in `yii\widgets\MaskedInput` (WinterSilence) +- Bug #19445: Fix caching in `yii\i18n\Formatter::getUnitMessage()` (WinterSilence) 2.0.45 February 11, 2022 diff --git a/framework/i18n/Formatter.php b/framework/i18n/Formatter.php index e1bdbc43c63..82af552007b 100644 --- a/framework/i18n/Formatter.php +++ b/framework/i18n/Formatter.php @@ -1643,8 +1643,8 @@ private function formatUnit($unitType, $unitFormat, $value, $decimals, $options, */ private function getUnitMessage($unitType, $unitFormat, $system, $position) { - if (isset($this->_unitMessages[$unitType][$system][$position])) { - return $this->_unitMessages[$unitType][$system][$position]; + if (isset($this->_unitMessages[$unitType][$unitFormat][$system][$position])) { + return $this->_unitMessages[$unitType][$unitFormat][$system][$position]; } if (!$this->_intlLoaded) { throw new InvalidConfigException('Format of ' . $unitType . ' is only supported when PHP intl extension is installed.'); @@ -1676,7 +1676,7 @@ private function getUnitMessage($unitType, $unitFormat, $system, $position) $message[] = "$key{{$value}}"; } - return $this->_unitMessages[$unitType][$system][$position] = '{n, plural, ' . implode(' ', $message) . '}'; + return $this->_unitMessages[$unitType][$unitFormat][$system][$position] = '{n, plural, ' . implode(' ', $message) . '}'; } /** diff --git a/tests/framework/i18n/FormatterTest.php b/tests/framework/i18n/FormatterTest.php index 300f2b7148f..9e8d4df6ca5 100644 --- a/tests/framework/i18n/FormatterTest.php +++ b/tests/framework/i18n/FormatterTest.php @@ -34,14 +34,15 @@ protected function setUp() 'timeZone' => 'UTC', 'language' => 'ru-RU', ]); - $this->formatter = new Formatter(['locale' => 'en-US']); + if (!isset($this->formatter)) { + $this->formatter = new Formatter(['locale' => 'en-US']); + } } protected function tearDown() { parent::tearDown(); IntlTestHelper::resetIntlStatus(); - $this->formatter = null; } public function testFormat()