diff options
author | diosmosis <benaka@piwik.pro> | 2015-10-20 06:00:10 +0300 |
---|---|---|
committer | diosmosis <benaka@piwik.pro> | 2015-10-20 06:00:10 +0300 |
commit | 51022df534c24132d6837191be4100aef64a3b3d (patch) | |
tree | 798cd9eabe18c16767c5d9d5bf1299ab5ab6dff0 /core/NumberFormatter.php | |
parent | c79ebcc1c34d493248574fb292e2a0aec2445838 (diff) |
Partially move NumberFormatter to DI, refactor NumberFormatterTest so not as many deprecated classes/methods are used, and add tests for NumberFormatter::format().
Diffstat (limited to 'core/NumberFormatter.php')
-rw-r--r-- | core/NumberFormatter.php | 36 |
1 files changed, 26 insertions, 10 deletions
diff --git a/core/NumberFormatter.php b/core/NumberFormatter.php index 64fb04b49f..2b8656b83a 100644 --- a/core/NumberFormatter.php +++ b/core/NumberFormatter.php @@ -7,13 +7,15 @@ * */ namespace Piwik; +use Piwik\Container\StaticContainer; +use Piwik\Translation\Translator; /** * Class NumberFormatter * * Used to format numbers according to current language */ -class NumberFormatter extends Singleton +class NumberFormatter { /** @var string language specific patterns for numbers */ protected $patternNumber; @@ -51,18 +53,23 @@ class NumberFormatter extends Singleton /** * Loads all required data from Intl plugin * + * TODO: instead of going directly through Translator, there should be a specific class + * that gets needed characters (ie, NumberFormatSource). The default implementation + * can use the Translator. This will make it easier to unit test NumberFormatter, + * w/o needing the Piwik Environment. + * * @return NumberFormatter */ - public function __construct() + public function __construct(Translator $translator) { - $this->patternNumber = Piwik::translate('Intl_NumberFormatNumber'); - $this->patternCurrency = Piwik::translate('Intl_NumberFormatCurrency'); - $this->patternPercent = Piwik::translate('Intl_NumberFormatPercent'); - $this->symbolPlus = Piwik::translate('Intl_NumberSymbolPlus'); - $this->symbolMinus = Piwik::translate('Intl_NumberSymbolMinus'); - $this->symbolPercent = Piwik::translate('Intl_NumberSymbolPercent'); - $this->symbolGroup = Piwik::translate('Intl_NumberSymbolGroup'); - $this->symbolDecimal = Piwik::translate('Intl_NumberSymbolDecimal'); + $this->patternNumber = $translator->translate('Intl_NumberFormatNumber'); + $this->patternCurrency = $translator->translate('Intl_NumberFormatCurrency'); + $this->patternPercent = $translator->translate('Intl_NumberFormatPercent'); + $this->symbolPlus = $translator->translate('Intl_NumberSymbolPlus'); + $this->symbolMinus = $translator->translate('Intl_NumberSymbolMinus'); + $this->symbolPercent = $translator->translate('Intl_NumberSymbolPercent'); + $this->symbolGroup = $translator->translate('Intl_NumberSymbolGroup'); + $this->symbolDecimal = $translator->translate('Intl_NumberSymbolDecimal'); } /** @@ -306,4 +313,13 @@ class NumberFormatter extends Singleton { return $value < 0; } + + /** + * @deprecated + * @return self + */ + public static function getInstance() + { + return StaticContainer::get('Piwik\NumberFormatter'); + } }
\ No newline at end of file |