1 | <?php |
||
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 amount or not |
||
44 | * |
||
45 | * @var boolean $sign_b4 |
||
46 | */ |
||
47 | private $sign_b4; |
||
48 | |||
49 | /** |
||
50 | * Space (or nothing) displayed between currency sign and amount |
||
51 | * |
||
52 | * @var string $sign_separator |
||
53 | */ |
||
54 | private $sign_separator; |
||
55 | |||
56 | /** |
||
57 | * How many digits should come after the decimal place |
||
58 | * Although not theoretically true, it can effectively |
||
59 | * be considered that all currencies are decimal based. |
||
60 | * Therefore the number of decimal places can be used |
||
61 | * to calculate number of subunits like so: |
||
62 | * subunits = pow( 10, decimal places ) |
||
63 | * |
||
64 | * @var int $decimal_places |
||
65 | */ |
||
66 | private $decimal_places; |
||
67 | |||
68 | /** |
||
69 | * Symbol to use for decimal mark |
||
70 | * |
||
71 | * @var string $decimal_mark |
||
72 | * eg '.' |
||
73 | */ |
||
74 | private $decimal_mark; |
||
75 | |||
76 | /** |
||
77 | * Symbol to use for thousands |
||
78 | * |
||
79 | * @var string $thousands |
||
80 | * eg ',' |
||
81 | */ |
||
82 | private $thousands; |
||
83 | |||
84 | /** |
||
85 | * The number of fractional divisions of a currency's main unit |
||
86 | * Can be used to determine the number of decimal places used. |
||
87 | * Because |
||
88 | * subunits = pow( 10, decimal places ) |
||
89 | * then |
||
90 | * decimal places = log( subunits ) |
||
91 | * except that a result of 1 means there are zero decimal places |
||
92 | * |
||
93 | * @var int |
||
94 | */ |
||
95 | private $subunits; |
||
96 | |||
97 | |||
98 | /** |
||
99 | * Currency constructor. |
||
100 | * |
||
101 | * @param string $code |
||
102 | * @param Label $label |
||
103 | * @param string $sign |
||
104 | * @param bool $sign_b4 |
||
105 | * @param int $decimal_places the number of decimal places to use when DISPLAYING the currency |
||
106 | * @param string $decimal_mark |
||
107 | * @param string $thousands |
||
108 | * @param int $subunits number of fractional divisions of a currency's main unit |
||
109 | * @param string $sign_separator |
||
110 | */ |
||
111 | public function __construct( |
||
132 | |||
133 | |||
134 | |||
135 | /** |
||
136 | * returns true if this currency is the same as the supplied currency |
||
137 | * |
||
138 | * @param Currency $other |
||
139 | * @return bool |
||
140 | */ |
||
141 | public function equals(Currency $other) |
||
145 | |||
146 | |||
147 | |||
148 | /** |
||
149 | * @return string |
||
150 | */ |
||
151 | public function code() |
||
155 | |||
156 | |||
157 | |||
158 | /** |
||
159 | * @return string |
||
160 | */ |
||
161 | public function name() |
||
165 | |||
166 | |||
167 | |||
168 | /** |
||
169 | * @return string |
||
170 | */ |
||
171 | public function plural() |
||
175 | |||
176 | |||
177 | |||
178 | /** |
||
179 | * @return string |
||
180 | */ |
||
181 | public function sign() |
||
185 | |||
186 | |||
187 | |||
188 | /** |
||
189 | * @return bool |
||
190 | */ |
||
191 | public function signB4() |
||
195 | |||
196 | |||
197 | /** |
||
198 | * @return string |
||
199 | */ |
||
200 | public function signSeparator() |
||
204 | |||
205 | |||
206 | |||
207 | /** |
||
208 | * @return int |
||
209 | */ |
||
210 | public function decimalPlaces() |
||
214 | |||
215 | |||
216 | |||
217 | /** |
||
218 | * @return string |
||
219 | */ |
||
220 | public function decimalMark() |
||
224 | |||
225 | |||
226 | |||
227 | /** |
||
228 | * @return string |
||
229 | */ |
||
230 | public function thousands() |
||
234 | |||
235 | |||
236 | /** |
||
237 | * The number of divisions of the currency's main unit that comprises the smallest units |
||
238 | * ex: 1 US Dollar has 100 Pennies, so USD subunits = 100 |
||
239 | * **WARNING** |
||
240 | * Some currencies, such as the Japanese Yen have no subunits, |
||
241 | * ie: the main unit is the smallest division |
||
242 | * so you need to always check that subunits is not zero |
||
243 | * before performing multiplication or division with it |
||
244 | * |
||
245 | * @return int |
||
246 | */ |
||
247 | public function subunits() |
||
251 | |||
252 | |||
253 | |||
254 | /** |
||
255 | * @return string |
||
256 | */ |
||
257 | public function __toString() |
||
261 | |||
262 | |||
263 | |||
264 | } |
||
265 | // End of file Currency.php |
||
267 |