|
2 | 2 |
|
3 | 3 | namespace PhpOffice\PhpSpreadsheet\Style\NumberFormat\Wizard;
|
4 | 4 |
|
5 |
| -use NumberFormatter; |
6 |
| -use PhpOffice\PhpSpreadsheet\Exception; |
7 |
| - |
8 |
| -class Currency extends Number |
| 5 | +class Currency extends CurrencyBase |
9 | 6 | {
|
10 |
| - public const LEADING_SYMBOL = true; |
11 |
| - |
12 |
| - public const TRAILING_SYMBOL = false; |
13 |
| - |
14 |
| - public const SYMBOL_WITH_SPACING = true; |
15 |
| - |
16 |
| - public const SYMBOL_WITHOUT_SPACING = false; |
17 |
| - |
18 |
| - protected string $currencyCode = '$'; |
19 |
| - |
20 |
| - protected bool $currencySymbolPosition = self::LEADING_SYMBOL; |
21 |
| - |
22 |
| - protected bool $currencySymbolSpacing = self::SYMBOL_WITHOUT_SPACING; |
23 |
| - |
24 |
| - protected const DEFAULT_STRIP_LEADING_RLM = false; |
25 |
| - |
26 |
| - protected bool $stripLeadingRLM = self::DEFAULT_STRIP_LEADING_RLM; |
27 |
| - |
28 |
| - /** |
29 |
| - * @param string $currencyCode the currency symbol or code to display for this mask |
30 |
| - * @param int $decimals number of decimal places to display, in the range 0-30 |
31 |
| - * @param bool $thousandsSeparator indicator whether the thousands separator should be used, or not |
32 |
| - * @param bool $currencySymbolPosition indicates whether the currency symbol comes before or after the value |
33 |
| - * Possible values are Currency::LEADING_SYMBOL and Currency::TRAILING_SYMBOL |
34 |
| - * @param bool $currencySymbolSpacing indicates whether there is spacing between the currency symbol and the value |
35 |
| - * Possible values are Currency::SYMBOL_WITH_SPACING and Currency::SYMBOL_WITHOUT_SPACING |
36 |
| - * @param ?string $locale Set the locale for the currency format; or leave as the default null. |
37 |
| - * If provided, Locale values must be a valid formatted locale string (e.g. 'en-GB', 'fr', uz-Arab-AF). |
38 |
| - * Note that setting a locale will override any other settings defined in this class |
39 |
| - * other than the currency code; or decimals (unless the decimals value is set to 0). |
40 |
| - * @param bool $stripLeadingRLM remove leading RLM added with |
41 |
| - * ICU 72.1+. |
42 |
| - * |
43 |
| - * @throws Exception If a provided locale code is not a valid format |
44 |
| - */ |
45 |
| - public function __construct( |
46 |
| - string $currencyCode = '$', |
47 |
| - int $decimals = 2, |
48 |
| - bool $thousandsSeparator = true, |
49 |
| - bool $currencySymbolPosition = self::LEADING_SYMBOL, |
50 |
| - bool $currencySymbolSpacing = self::SYMBOL_WITHOUT_SPACING, |
51 |
| - ?string $locale = null, |
52 |
| - bool $stripLeadingRLM = self::DEFAULT_STRIP_LEADING_RLM |
53 |
| - ) { |
54 |
| - $this->setCurrencyCode($currencyCode); |
55 |
| - $this->setThousandsSeparator($thousandsSeparator); |
56 |
| - $this->setDecimals($decimals); |
57 |
| - $this->setCurrencySymbolPosition($currencySymbolPosition); |
58 |
| - $this->setCurrencySymbolSpacing($currencySymbolSpacing); |
59 |
| - $this->setLocale($locale); |
60 |
| - $this->stripLeadingRLM = $stripLeadingRLM; |
61 |
| - } |
62 |
| - |
63 |
| - public function setCurrencyCode(string $currencyCode): void |
64 |
| - { |
65 |
| - $this->currencyCode = $currencyCode; |
66 |
| - } |
67 |
| - |
68 |
| - public function setCurrencySymbolPosition(bool $currencySymbolPosition = self::LEADING_SYMBOL): void |
69 |
| - { |
70 |
| - $this->currencySymbolPosition = $currencySymbolPosition; |
71 |
| - } |
72 |
| - |
73 |
| - public function setCurrencySymbolSpacing(bool $currencySymbolSpacing = self::SYMBOL_WITHOUT_SPACING): void |
74 |
| - { |
75 |
| - $this->currencySymbolSpacing = $currencySymbolSpacing; |
76 |
| - } |
77 |
| - |
78 |
| - public function setStripLeadingRLM(bool $stripLeadingRLM): void |
79 |
| - { |
80 |
| - $this->stripLeadingRLM = $stripLeadingRLM; |
81 |
| - } |
82 |
| - |
83 |
| - protected function getLocaleFormat(): string |
84 |
| - { |
85 |
| - $formatter = new Locale($this->fullLocale, NumberFormatter::CURRENCY); |
86 |
| - $mask = $formatter->format($this->stripLeadingRLM); |
87 |
| - if ($this->decimals === 0) { |
88 |
| - $mask = (string) preg_replace('/\.0+/miu', '', $mask); |
89 |
| - } |
90 |
| - |
91 |
| - return str_replace('¤', $this->formatCurrencyCode(), $mask); |
92 |
| - } |
93 |
| - |
94 |
| - private function formatCurrencyCode(): string |
95 |
| - { |
96 |
| - if ($this->locale === null) { |
97 |
| - return $this->currencyCode; |
98 |
| - } |
99 |
| - |
100 |
| - return "[\${$this->currencyCode}-{$this->locale}]"; |
101 |
| - } |
102 |
| - |
103 |
| - public function format(): string |
104 |
| - { |
105 |
| - if ($this->localeFormat !== null) { |
106 |
| - return $this->localeFormat; |
107 |
| - } |
| 7 | + protected ?bool $overrideSpacing = false; |
108 | 8 |
|
109 |
| - return sprintf( |
110 |
| - '%s%s%s0%s%s%s', |
111 |
| - $this->currencySymbolPosition === self::LEADING_SYMBOL ? $this->formatCurrencyCode() : null, |
112 |
| - ( |
113 |
| - $this->currencySymbolPosition === self::LEADING_SYMBOL |
114 |
| - && $this->currencySymbolSpacing === self::SYMBOL_WITH_SPACING |
115 |
| - ) ? "\u{a0}" : '', |
116 |
| - $this->thousandsSeparator ? '#,##' : null, |
117 |
| - $this->decimals > 0 ? '.' . str_repeat('0', $this->decimals) : null, |
118 |
| - ( |
119 |
| - $this->currencySymbolPosition === self::TRAILING_SYMBOL |
120 |
| - && $this->currencySymbolSpacing === self::SYMBOL_WITH_SPACING |
121 |
| - ) ? "\u{a0}" : '', |
122 |
| - $this->currencySymbolPosition === self::TRAILING_SYMBOL ? $this->formatCurrencyCode() : null |
123 |
| - ); |
124 |
| - } |
| 9 | + protected ?string $overrideNegative = null; |
125 | 10 | }
|
0 commit comments