1 | <?php |
||
23 | class NumberFormatter implements FormatterInterface, LocalizableInterface, FormatterNumberInterface |
||
24 | { |
||
25 | public const NO_BREAK_SPACE_HEX = 'c2a0'; |
||
26 | public const NARROW_NO_BREAK_SPACE_HEX = 'e280af'; |
||
27 | |||
28 | /** |
||
29 | * Formatter instances. |
||
30 | * |
||
31 | * @var array |
||
32 | */ |
||
33 | protected $formatters = []; |
||
34 | |||
35 | /** |
||
36 | * @var array |
||
37 | */ |
||
38 | protected $params = []; |
||
39 | |||
40 | /** |
||
41 | * @var array |
||
42 | */ |
||
43 | protected $default_params = [ |
||
44 | 'decimals' => 2, |
||
45 | 'locale' => null, |
||
46 | 'pattern' => null, |
||
47 | 'disableUseOfNonBreakingSpaces' => false |
||
48 | ]; |
||
49 | |||
50 | /** |
||
51 | * @param array $params |
||
52 | * |
||
53 | * @throws Exception\ExtensionNotLoadedException if ext/intl is not present |
||
54 | * @throws Exception\InvalidArgumentException |
||
55 | */ |
||
56 | 24 | public function __construct(array $params = []) |
|
73 | |||
74 | /** |
||
75 | * @throws Exception\InvalidArgumentException |
||
76 | * |
||
77 | * @param array $params |
||
78 | */ |
||
79 | 24 | protected function setParams($params) |
|
90 | |||
91 | 12 | protected function initWhitespaceSeparator(IntlNumberFormatter $formatter): void |
|
102 | |||
103 | 6 | protected function loadFormatterId(string $formatterId): void |
|
119 | |||
120 | /** |
||
121 | * Format a number. |
||
122 | * |
||
123 | * @param float $number |
||
124 | * |
||
125 | * @return string |
||
126 | */ |
||
127 | 3 | public function format($number, ArrayObject $row = null): string |
|
142 | |||
143 | /** |
||
144 | * Throws an Exception when number cannot be formatted. |
||
145 | * |
||
146 | * @param IntlNumberFormatter $intlFormatter |
||
147 | * @param int|string|float $number |
||
148 | * |
||
149 | * @throws Exception\RuntimeException |
||
150 | */ |
||
151 | 4 | protected function throwNumberFormatterException(IntlNumberFormatter $intlFormatter, $number): void |
|
161 | |||
162 | /** |
||
163 | * Set locale to use instead of the default. |
||
164 | * |
||
165 | * @param string $locale |
||
166 | */ |
||
167 | 17 | public function setLocale(?string $locale): self |
|
173 | |||
174 | /** |
||
175 | * Get the locale to use. |
||
176 | * |
||
177 | * @return string|null |
||
178 | */ |
||
179 | 6 | public function getLocale(): ?string |
|
183 | |||
184 | /** |
||
185 | * Set decimals. |
||
186 | * |
||
187 | * @param int $decimals |
||
188 | */ |
||
189 | 15 | public function setDecimals($decimals): self |
|
195 | |||
196 | /** |
||
197 | * @return int |
||
198 | */ |
||
199 | 6 | public function getDecimals(): int |
|
203 | |||
204 | /** |
||
205 | * Set the number pattern, (#,##0.###, ....). |
||
206 | * |
||
207 | * @see http://php.net/manual/en/numberformatter.setpattern.php |
||
208 | * |
||
209 | * @param string $pattern |
||
210 | */ |
||
211 | 8 | public function setPattern($pattern): self |
|
217 | |||
218 | /** |
||
219 | * Get the number pattern. |
||
220 | * |
||
221 | * @return string|null |
||
222 | */ |
||
223 | 6 | public function getPattern(): ?string |
|
227 | |||
228 | 3 | public function setDisableUseOfNonBreakingSpaces(bool $disable=true): self { |
|
232 | } |
||
233 |