1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Mailcode; |
6
|
|
|
|
7
|
|
|
use AppUtils\OperationResult; |
8
|
|
|
|
9
|
|
|
class Mailcode_Number_LocalCurrency extends OperationResult |
10
|
|
|
{ |
11
|
|
|
public const DEFAULT_COUNTRY = "US"; |
12
|
|
|
public const DEFAULT_CURRENCY_NAME = "USD"; |
13
|
|
|
public const DEFAULT_CURRENCY_SYMBOL = "$"; |
14
|
|
|
public const DEFAULT_UNIT_SEPARATOR = " "; |
15
|
|
|
public const DEFAULT_FORMAT = "1,000.00"; |
16
|
|
|
|
17
|
|
|
private string $country; |
18
|
|
|
private string $currencyName; |
19
|
|
|
private string $currencySymbol; |
20
|
|
|
private string $unitSeparator; |
21
|
|
|
private string $formatString; |
22
|
|
|
|
23
|
|
|
private ?Mailcode_Parser_Statement_Tokenizer_Token_Variable $currency = null; |
24
|
|
|
private ?Mailcode_Parser_Statement_Tokenizer_Token_Variable $region = null; |
25
|
|
|
|
26
|
|
|
private static ?Mailcode_Number_LocalCurrency $instance = null; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @param string $country |
30
|
|
|
* @param string $currencyName |
31
|
|
|
* @param string $currencySymbol |
32
|
|
|
* @param string $unitSeparator |
33
|
|
|
* @param string $formatString |
34
|
|
|
* @param ?Mailcode_Parser_Statement_Tokenizer_Token $currency |
35
|
|
|
* @param ?Mailcode_Parser_Statement_Tokenizer_Token $region |
36
|
|
|
*/ |
37
|
|
|
public function __construct(string $country, |
38
|
|
|
string $currencyName, |
39
|
|
|
string $currencySymbol, |
40
|
|
|
string $unitSeparator, |
41
|
|
|
string $formatString, |
42
|
|
|
?Mailcode_Parser_Statement_Tokenizer_Token $currency = null, |
43
|
|
|
?Mailcode_Parser_Statement_Tokenizer_Token $region = null) |
44
|
|
|
{ |
45
|
|
|
$this->country = $country; |
46
|
|
|
$this->currencyName = $currencyName; |
47
|
|
|
$this->currencySymbol = $currencySymbol; |
48
|
|
|
$this->unitSeparator = $unitSeparator; |
49
|
|
|
$this->formatString = $formatString; |
50
|
|
|
|
51
|
|
|
$this->currency = $currency; |
52
|
|
|
$this->region = $region; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function getCountry(): string |
56
|
|
|
{ |
57
|
|
|
return $this->country; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function getCurrencyName(): string |
61
|
|
|
{ |
62
|
|
|
return $this->currencyName; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function getCurrencySymbol(): string |
66
|
|
|
{ |
67
|
|
|
return $this->currencySymbol; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function getUnitSeparator(): string |
71
|
|
|
{ |
72
|
|
|
return $this->unitSeparator; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function getFormatString(): string |
76
|
|
|
{ |
77
|
|
|
return $this->formatString; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function getRegion(): ?Mailcode_Parser_Statement_Tokenizer_Token |
81
|
|
|
{ |
82
|
|
|
return $this->region; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function getCurrency(): ?Mailcode_Parser_Statement_Tokenizer_Token |
86
|
|
|
{ |
87
|
|
|
return $this->currency; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function withRegion(?Mailcode_Parser_Statement_Tokenizer_Token $region = null): Mailcode_Number_LocalCurrency |
91
|
|
|
{ |
92
|
|
|
return new Mailcode_Number_LocalCurrency( |
93
|
|
|
$this->country, |
94
|
|
|
$this->currencyName, |
95
|
|
|
$this->currencySymbol, |
96
|
|
|
$this->unitSeparator, |
97
|
|
|
$this->formatString, |
98
|
|
|
$this->currency, |
99
|
|
|
$region |
100
|
|
|
); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
public function withCurrency(?Mailcode_Parser_Statement_Tokenizer_Token $currency = null): Mailcode_Number_LocalCurrency |
104
|
|
|
{ |
105
|
|
|
return new Mailcode_Number_LocalCurrency( |
106
|
|
|
$this->country, |
107
|
|
|
$this->currencyName, |
108
|
|
|
$this->currencySymbol, |
109
|
|
|
$this->unitSeparator, |
110
|
|
|
$this->formatString, |
111
|
|
|
$currency, |
112
|
|
|
$this->region |
113
|
|
|
); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
public function getFormatInfo(): Mailcode_Number_Info |
117
|
|
|
{ |
118
|
|
|
return new Mailcode_Number_Info($this->formatString); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
public static function defaultInstance(): Mailcode_Number_LocalCurrency |
122
|
|
|
{ |
123
|
|
|
if (!isset(self::$instance)) { |
124
|
|
|
self::$instance = new self( |
125
|
|
|
self::DEFAULT_COUNTRY, |
126
|
|
|
self::DEFAULT_CURRENCY_NAME, |
127
|
|
|
self::DEFAULT_CURRENCY_SYMBOL, |
128
|
|
|
self::DEFAULT_UNIT_SEPARATOR, |
129
|
|
|
self::DEFAULT_FORMAT |
130
|
|
|
); |
131
|
|
|
} |
132
|
|
|
return self::$instance; |
|
|
|
|
133
|
|
|
} |
134
|
|
|
} |