-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathConfig.php
170 lines (164 loc) · 6.17 KB
/
Config.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<?php declare(strict_types = 1);
namespace LastDragon_ru\LaraASP\Formatter\Config;
use Exception;
use IntlDateFormatter;
use LastDragon_ru\LaraASP\Core\Application\Configuration\Configuration;
use LastDragon_ru\LaraASP\Formatter\Formats\Duration\DurationFormat;
use LastDragon_ru\LaraASP\Formatter\Formats\Duration\DurationOptions;
use LastDragon_ru\LaraASP\Formatter\Formats\Filesize\FilesizeFormat;
use LastDragon_ru\LaraASP\Formatter\Formats\Filesize\FilesizeOptions;
use LastDragon_ru\LaraASP\Formatter\Formats\IntlDateTime\IntlDateTimeFormat;
use LastDragon_ru\LaraASP\Formatter\Formats\IntlDateTime\IntlDateTimeOptions;
use LastDragon_ru\LaraASP\Formatter\Formats\IntlNumber\IntlCurrencyFormat;
use LastDragon_ru\LaraASP\Formatter\Formats\IntlNumber\IntlNumberFormat;
use LastDragon_ru\LaraASP\Formatter\Formats\IntlNumber\IntlNumberOptions;
use LastDragon_ru\LaraASP\Formatter\Formats\Secret\SecretFormat;
use LastDragon_ru\LaraASP\Formatter\Formats\Secret\SecretOptions;
use LastDragon_ru\LaraASP\Formatter\Formats\String\StringFormat;
use LastDragon_ru\LaraASP\Formatter\Formatter;
use NumberFormatter;
use Override;
class Config extends Configuration {
public function __construct(
/**
* @var array<string, Format<*, mixed>>
*/
public array $formats = [],
/**
* Global Intl settings (for all formats/locales).
*/
public ?Intl $intl = null,
) {
parent::__construct();
$this->intl = new Intl(
number: new IntlNumberOptions(
attributes: [
NumberFormatter::ROUNDING_MODE => NumberFormatter::ROUND_HALFUP,
],
),
);
$this->formats[Formatter::String] = new Format(StringFormat::class);
$this->formats[Formatter::Secret] = new Format(SecretFormat::class, new SecretOptions(5));
$this->formats[Formatter::Integer] = new Format(
IntlNumberFormat::class,
new IntlNumberOptions(
style : NumberFormatter::DECIMAL,
attributes: [
NumberFormatter::FRACTION_DIGITS => 0,
],
),
);
$this->formats[Formatter::Decimal] = new Format(
IntlNumberFormat::class,
new IntlNumberOptions(
style : NumberFormatter::DECIMAL,
attributes: [
NumberFormatter::FRACTION_DIGITS => 2,
],
),
);
$this->formats[Formatter::Scientific] = new Format(
IntlNumberFormat::class,
new IntlNumberOptions(
style: NumberFormatter::SCIENTIFIC,
),
);
$this->formats[Formatter::Spellout] = new Format(
IntlNumberFormat::class,
new IntlNumberOptions(
style: NumberFormatter::SPELLOUT,
),
);
$this->formats[Formatter::Ordinal] = new Format(
IntlNumberFormat::class,
new IntlNumberOptions(
style: NumberFormatter::ORDINAL,
),
);
$this->formats[Formatter::Percent] = new Format(
IntlNumberFormat::class,
new IntlNumberOptions(
style : NumberFormatter::PERCENT,
attributes: [
NumberFormatter::FRACTION_DIGITS => 0,
],
),
);
$this->formats[Formatter::Currency] = new Format(
IntlCurrencyFormat::class,
);
$this->formats[Formatter::Duration] = new Format(
DurationFormat::class,
new DurationOptions(
'HH:mm:ss.SSS',
),
);
$this->formats[Formatter::Time] = new Format(
IntlDateTimeFormat::class,
new IntlDateTimeOptions(
dateType: IntlDateFormatter::NONE,
timeType: IntlDateFormatter::SHORT,
),
);
$this->formats[Formatter::Date] = new Format(
IntlDateTimeFormat::class,
new IntlDateTimeOptions(
dateType: IntlDateFormatter::SHORT,
timeType: IntlDateFormatter::NONE,
),
);
$this->formats[Formatter::DateTime] = new Format(
IntlDateTimeFormat::class,
new IntlDateTimeOptions(
dateType: IntlDateFormatter::SHORT,
timeType: IntlDateFormatter::SHORT,
),
);
$this->formats[Formatter::Disksize] = new Format(
FilesizeFormat::class,
new FilesizeOptions(
base : 1000,
units: [
['disksize.B', 'B'],
['disksize.kB', 'kB'],
['disksize.MB', 'MB'],
['disksize.GB', 'GB'],
['disksize.TB', 'TB'],
['disksize.PB', 'PB'],
['disksize.EB', 'EB'],
['disksize.ZB', 'ZB'],
['disksize.YB', 'YB'],
['disksize.RB', 'RB'],
['disksize.QB', 'QB'],
],
),
);
$this->formats[Formatter::Filesize] = new Format(
FilesizeFormat::class,
new FilesizeOptions(
base : 1024,
units: [
['filesize.B', 'B'],
['filesize.KiB', 'KiB'],
['filesize.MiB', 'MiB'],
['filesize.GiB', 'GiB'],
['filesize.TiB', 'TiB'],
['filesize.PiB', 'PiB'],
['filesize.EiB', 'EiB'],
['filesize.ZiB', 'ZiB'],
['filesize.YiB', 'YiB'],
['filesize.RiB', 'RiB'],
['filesize.QiB', 'QiB'],
],
),
);
}
/**
* @deprecated 7.0.0 Array-based config is deprecated. Please migrate to object-based config.
* @inheritDoc
*/
#[Override]
public static function fromArray(array $array): static {
throw new Exception('Array-based config is not supported anymore. Please migrate to object-based config.');
}
}