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 static ?Mailcode_Number_LocalCurrency $instance = null; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @param string $country |
27
|
|
|
* @param string $currencyName |
28
|
|
|
* @param string $currencySymbol |
29
|
|
|
* @param string $unitSeparator |
30
|
|
|
* @param string $formatString |
31
|
|
|
*/ |
32
|
|
|
public function __construct(string $country, string $currencyName, string $currencySymbol, string $unitSeparator, string $formatString) |
33
|
|
|
{ |
34
|
|
|
$this->country = $country; |
35
|
|
|
$this->currencyName = $currencyName; |
36
|
|
|
$this->currencySymbol = $currencySymbol; |
37
|
|
|
$this->unitSeparator = $unitSeparator; |
38
|
|
|
$this->formatString = $formatString; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function getCountry(): string |
42
|
|
|
{ |
43
|
|
|
return $this->country; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function getCurrencyName(): string |
47
|
|
|
{ |
48
|
|
|
return $this->currencyName; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function getCurrencySymbol(): string |
52
|
|
|
{ |
53
|
|
|
return $this->currencySymbol; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function getUnitSeparator(): string |
57
|
|
|
{ |
58
|
|
|
return $this->unitSeparator; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function getFormatString(): string |
62
|
|
|
{ |
63
|
|
|
return $this->formatString; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function getFormatInfo(): Mailcode_Number_Info |
67
|
|
|
{ |
68
|
|
|
return new Mailcode_Number_Info($this->formatString); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public static function defaultInstance(): Mailcode_Number_LocalCurrency |
72
|
|
|
{ |
73
|
|
|
if (!isset(self::$instance)) { |
74
|
|
|
self::$instance = new self( |
75
|
|
|
self::DEFAULT_COUNTRY, |
76
|
|
|
self::DEFAULT_CURRENCY_NAME, |
77
|
|
|
self::DEFAULT_CURRENCY_SYMBOL, |
78
|
|
|
self::DEFAULT_UNIT_SEPARATOR, |
79
|
|
|
self::DEFAULT_FORMAT |
80
|
|
|
); |
81
|
|
|
} |
82
|
|
|
return self::$instance; |
|
|
|
|
83
|
|
|
} |
84
|
|
|
} |