1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace EventEspresso\core\domain\values\currency; |
4
|
|
|
|
5
|
|
|
use EventEspresso\core\entities\Label; |
6
|
|
|
|
7
|
|
|
defined('EVENT_ESPRESSO_VERSION') || exit; |
8
|
|
|
|
9
|
|
|
|
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class Currency |
13
|
|
|
* DTO for data pertaining to a currency |
14
|
|
|
* |
15
|
|
|
* @package Event Espresso |
16
|
|
|
* @author Brent Christensen |
17
|
|
|
* @since $VID:$ |
18
|
|
|
*/ |
19
|
|
|
class Currency |
20
|
|
|
{ |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* eg 'US' |
24
|
|
|
* |
25
|
|
|
* @var string $code |
26
|
|
|
*/ |
27
|
|
|
private $code; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var Label $label |
31
|
|
|
*/ |
32
|
|
|
private $label; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* currency sign |
36
|
|
|
* |
37
|
|
|
* @var string $sign |
38
|
|
|
* eg '$' |
39
|
|
|
*/ |
40
|
|
|
private $sign; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Whether the currency sign should come before the number or not |
44
|
|
|
* |
45
|
|
|
* @var boolean $sign_b4 |
46
|
|
|
*/ |
47
|
|
|
private $sign_b4; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* How many digits should come after the decimal place |
51
|
|
|
* |
52
|
|
|
* @var int $decimal_places |
53
|
|
|
*/ |
54
|
|
|
private $decimal_places; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Symbol to use for decimal mark |
58
|
|
|
* |
59
|
|
|
* @var string $decimal_mark |
60
|
|
|
* eg '.' |
61
|
|
|
*/ |
62
|
|
|
private $decimal_mark; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Symbol to use for thousands |
66
|
|
|
* |
67
|
|
|
* @var string $thousands |
68
|
|
|
* eg ',' |
69
|
|
|
*/ |
70
|
|
|
private $thousands; |
71
|
|
|
|
72
|
|
|
|
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Currency constructor. |
76
|
|
|
* |
77
|
|
|
* @param string $code |
78
|
|
|
* @param Label $label |
79
|
|
|
* @param string $sign |
80
|
|
|
* @param bool $sign_b4 |
81
|
|
|
* @param int $decimal_places |
82
|
|
|
* @param string $decimal_mark |
83
|
|
|
* @param string $thousands |
84
|
|
|
*/ |
85
|
|
|
public function __construct($code, Label $label, $sign, $sign_b4, $decimal_places, $decimal_mark, $thousands) |
86
|
|
|
{ |
87
|
|
|
$this->code = $code; |
88
|
|
|
$this->label = $label; |
89
|
|
|
$this->sign = $sign; |
90
|
|
|
$this->sign_b4 = $sign_b4; |
91
|
|
|
$this->decimal_places = $decimal_places; |
92
|
|
|
$this->decimal_mark = $decimal_mark; |
93
|
|
|
$this->thousands = $thousands; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
|
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* returns true if this currency is the same as the supplied currency |
100
|
|
|
* |
101
|
|
|
* @param Currency $other |
102
|
|
|
* @return bool |
103
|
|
|
*/ |
104
|
|
|
public function equals(Currency $other) |
105
|
|
|
{ |
106
|
|
|
return $this->code() === $other->code(); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
|
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @return string |
113
|
|
|
*/ |
114
|
|
|
public function code() |
115
|
|
|
{ |
116
|
|
|
return $this->code; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
|
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @return string |
123
|
|
|
*/ |
124
|
|
|
public function name() |
125
|
|
|
{ |
126
|
|
|
return $this->label->singular(); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
|
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* @return string |
133
|
|
|
*/ |
134
|
|
|
public function plural() |
135
|
|
|
{ |
136
|
|
|
return $this->label->plural(); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
|
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* @return string |
143
|
|
|
*/ |
144
|
|
|
public function sign() |
145
|
|
|
{ |
146
|
|
|
return $this->sign; |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
|
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* @return bool |
153
|
|
|
*/ |
154
|
|
|
public function signB4() |
155
|
|
|
{ |
156
|
|
|
return $this->sign_b4; |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
|
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* @return int |
163
|
|
|
*/ |
164
|
|
|
public function decimalPlaces() |
165
|
|
|
{ |
166
|
|
|
return $this->decimal_places; |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
|
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* @return string |
173
|
|
|
*/ |
174
|
|
|
public function decimalMark() |
175
|
|
|
{ |
176
|
|
|
return $this->decimal_mark; |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
|
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* @return string |
183
|
|
|
*/ |
184
|
|
|
public function thousands() |
185
|
|
|
{ |
186
|
|
|
return $this->thousands; |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
|
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* @return string |
193
|
|
|
*/ |
194
|
|
|
public function __toString() |
195
|
|
|
{ |
196
|
|
|
return $this->code(); |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
|
200
|
|
|
|
201
|
|
|
} |
202
|
|
|
// End of file Currency.php |
203
|
|
|
// Location: core/entities/money/Currency.php |
204
|
|
|
|