1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Adsmurai\Currency; |
4
|
|
|
|
5
|
|
|
use Adsmurai\Currency\Contracts\MoneyFormat as MoneyFormatInterface; |
6
|
|
|
|
7
|
|
|
final class MoneyFormat implements MoneyFormatInterface |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* @var string |
11
|
|
|
*/ |
12
|
|
|
private $decimalsSeparator; |
13
|
|
|
/** |
14
|
|
|
* @var string |
15
|
|
|
*/ |
16
|
|
|
private $thousandsSeparator; |
17
|
|
|
/** |
18
|
|
|
* @var int |
19
|
|
|
*/ |
20
|
|
|
private $extraPrecision; |
21
|
|
|
/** |
22
|
|
|
* @var int |
23
|
|
|
*/ |
24
|
|
|
private $decorationType; |
25
|
|
|
/** |
26
|
|
|
* @var int |
27
|
|
|
*/ |
28
|
|
|
private $precision; |
29
|
|
|
/** |
30
|
|
|
* @var int |
31
|
|
|
*/ |
32
|
|
|
private $decorationSpace; |
33
|
|
|
|
34
|
|
|
private function __construct( |
35
|
|
|
string $decimalsSeparator = self::DEFAULT_DECIMALS_SEPARATOR, |
36
|
|
|
string $thousandsSeparator = self::DEFAULT_THOUSANDS_SEPARATOR, |
37
|
|
|
int $decorationType = self::DECORATION_SYMBOL, |
38
|
|
|
int $decorationSpace = self::DECORATION_WITHOUT_SPACE, |
39
|
|
|
int $extraPrecision = 0, |
40
|
|
|
int $precision = null |
41
|
|
|
) { |
42
|
|
|
$this->decimalsSeparator = $decimalsSeparator; |
43
|
|
|
$this->thousandsSeparator = $thousandsSeparator; |
44
|
|
|
$this->extraPrecision = $extraPrecision; |
45
|
|
|
$this->decorationType = $decorationType; |
46
|
|
|
$this->precision = $precision; |
47
|
|
|
$this->decorationSpace = $decorationSpace; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public static function default(): MoneyFormatInterface |
|
|
|
|
51
|
|
|
{ |
52
|
|
|
return new self(); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
View Code Duplication |
public static function fromParameters( |
|
|
|
|
56
|
|
|
string $decimalsSeparator = self::DEFAULT_DECIMALS_SEPARATOR, |
57
|
|
|
string $thousandsSeparator = self::DEFAULT_THOUSANDS_SEPARATOR, |
58
|
|
|
int $decorationType = self::DECORATION_SYMBOL, |
59
|
|
|
int $decorationSpace = self::DECORATION_WITHOUT_SPACE |
60
|
|
|
): MoneyFormatInterface { |
61
|
|
|
return new self( |
62
|
|
|
$decimalsSeparator, |
63
|
|
|
$thousandsSeparator, |
64
|
|
|
$decorationType, |
65
|
|
|
$decorationSpace |
66
|
|
|
); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
View Code Duplication |
public static function fromParametersWithPrecision( |
|
|
|
|
70
|
|
|
int $precision, |
71
|
|
|
string $decimalsSeparator = self::DEFAULT_DECIMALS_SEPARATOR, |
72
|
|
|
string $thousandsSeparator = self::DEFAULT_THOUSANDS_SEPARATOR, |
73
|
|
|
int $decorationType = self::DECORATION_SYMBOL, |
74
|
|
|
int $decorationSpace = self::DECORATION_WITHOUT_SPACE |
75
|
|
|
): MoneyFormatInterface { |
76
|
|
|
return new self( |
77
|
|
|
$decimalsSeparator, |
78
|
|
|
$thousandsSeparator, |
79
|
|
|
$decorationType, |
80
|
|
|
$decorationSpace, |
81
|
|
|
0, |
82
|
|
|
$precision |
83
|
|
|
); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
View Code Duplication |
public static function fromParametersWithExtraPrecision( |
|
|
|
|
87
|
|
|
int $extraPrecision, |
88
|
|
|
string $decimalsSeparator = self::DEFAULT_DECIMALS_SEPARATOR, |
89
|
|
|
string $thousandsSeparator = self::DEFAULT_THOUSANDS_SEPARATOR, |
90
|
|
|
int $decorationType = self::DECORATION_SYMBOL, |
91
|
|
|
int $decorationSpace = self::DECORATION_WITHOUT_SPACE |
92
|
|
|
): MoneyFormatInterface { |
93
|
|
|
return new self( |
94
|
|
|
$decimalsSeparator, |
95
|
|
|
$thousandsSeparator, |
96
|
|
|
$decorationType, |
97
|
|
|
$decorationSpace, |
98
|
|
|
$extraPrecision |
99
|
|
|
); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @return string |
104
|
|
|
*/ |
105
|
|
|
public function getDecimalsSeparator(): string |
106
|
|
|
{ |
107
|
|
|
return $this->decimalsSeparator; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @return string |
112
|
|
|
*/ |
113
|
|
|
public function getThousandsSeparator(): string |
114
|
|
|
{ |
115
|
|
|
return $this->thousandsSeparator; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @return int |
120
|
|
|
*/ |
121
|
|
|
public function getExtraPrecision(): int |
122
|
|
|
{ |
123
|
|
|
return $this->extraPrecision; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @return int |
128
|
|
|
*/ |
129
|
|
|
public function getDecorationType(): int |
130
|
|
|
{ |
131
|
|
|
return $this->decorationType; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @return int|null |
136
|
|
|
*/ |
137
|
|
|
public function getPrecision() |
138
|
|
|
{ |
139
|
|
|
return $this->precision; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
public function getDecorationSpace(): int |
143
|
|
|
{ |
144
|
|
|
return $this->decorationSpace; |
145
|
|
|
} |
146
|
|
|
} |
147
|
|
|
|