|
9 | 9 | namespace Fastbolt\ExcelWriter;
|
10 | 10 |
|
11 | 11 | use Fastbolt\ExcelWriter\ColumnFormatter\ColumnFormatter;
|
| 12 | +use Fastbolt\ExcelWriter\ColumnFormatter\CurrencyFormatter; |
12 | 13 | use Fastbolt\ExcelWriter\ColumnFormatter\DateFormatter;
|
13 | 14 | use Fastbolt\ExcelWriter\ColumnFormatter\FloatFormatter;
|
14 | 15 | use Fastbolt\ExcelWriter\ColumnFormatter\IntegerFormatter;
|
|
17 | 18 |
|
18 | 19 | class ColumnSetting
|
19 | 20 | {
|
20 |
| - public const FORMAT_INTEGER = 'int'; |
21 |
| - public const FORMAT_FLOAT = 'float'; |
22 |
| - public const FORMAT_STRING = 'string'; |
23 |
| - public const FORMAT_DATE = 'datetime'; |
| 21 | + public const FORMAT_INTEGER = 'int'; |
| 22 | + public const FORMAT_FLOAT = 'float'; |
| 23 | + public const FORMAT_STRING = 'string'; |
| 24 | + public const FORMAT_DATE = 'datetime'; |
24 | 25 | public const FOMRAT_PERCENTAGE = 'percentage';
|
| 26 | + public const FORMAT_CURRENCY_EUR = 'currency_eur'; |
| 27 | + public const FORMAT_CURRENCY_USD = 'currency_usd'; |
25 | 28 |
|
26 | 29 | private string $format;
|
27 | 30 | private string $name = ''; //excel-name for the column
|
@@ -85,20 +88,16 @@ public function setName(string $name): ColumnSetting
|
85 | 88 | */
|
86 | 89 | public function getFormatter(): ColumnFormatter
|
87 | 90 | {
|
88 |
| - switch ($this->format) { |
89 |
| - case self::FORMAT_STRING: |
90 |
| - return new StringFormatter(); |
91 |
| - case self::FORMAT_DATE: |
92 |
| - return new DateFormatter(); |
93 |
| - case self::FORMAT_INTEGER: |
94 |
| - return new IntegerFormatter(); |
95 |
| - case self::FORMAT_FLOAT: |
96 |
| - return new FloatFormatter($this); |
97 |
| - case self::FOMRAT_PERCENTAGE: |
98 |
| - return new PercentageFormatter($this); |
99 |
| - } |
100 |
| - |
101 |
| - return new StringFormatter(); |
| 91 | + return match ($this->format) { |
| 92 | + self::FORMAT_STRING => new StringFormatter(), |
| 93 | + self::FORMAT_DATE => new DateFormatter(), |
| 94 | + self::FORMAT_INTEGER => new IntegerFormatter(), |
| 95 | + self::FORMAT_FLOAT => new FloatFormatter($this), |
| 96 | + self::FOMRAT_PERCENTAGE => new PercentageFormatter($this), |
| 97 | + self::FORMAT_CURRENCY_EUR => new CurrencyFormatter($this, CurrencyFormatter::CURRENCY_EUR), |
| 98 | + self::FORMAT_CURRENCY_USD => new CurrencyFormatter($this, CurrencyFormatter::CURRENCY_USD), |
| 99 | + default => new StringFormatter(), |
| 100 | + }; |
102 | 101 | }
|
103 | 102 |
|
104 | 103 | /**
|
|
0 commit comments