Skip to content

Commit

Permalink
Fix caching in Formatter::getUnitMessage() (#19445)
Browse files Browse the repository at this point in the history
* Fix caching in `Formatter::getUnitMessage()`

* Update FormatterTest.php

* Update CHANGELOG.md
  • Loading branch information
WinterSilence authored Jun 16, 2022
1 parent f72310c commit 474a67d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
1 change: 1 addition & 0 deletions framework/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions framework/i18n/Formatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
Expand Down Expand Up @@ -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) . '}';
}

/**
Expand Down
5 changes: 3 additions & 2 deletions tests/framework/i18n/FormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 474a67d

Please sign in to comment.