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 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 | * Although not theoretically true, it can effectively |
||
52 | * be considered that all currencies are decimal based. |
||
53 | * Therefore the number of decimal places can be used |
||
54 | * to calculate number of subunits like so: |
||
55 | * subunits = pow( 10, decimal places ) |
||
56 | * |
||
57 | * @var int $decimal_places |
||
58 | */ |
||
59 | private $decimal_places; |
||
60 | |||
61 | /** |
||
62 | * Symbol to use for decimal mark |
||
63 | * |
||
64 | * @var string $decimal_mark |
||
65 | * eg '.' |
||
66 | */ |
||
67 | private $decimal_mark; |
||
68 | |||
69 | /** |
||
70 | * Symbol to use for thousands |
||
71 | * |
||
72 | * @var string $thousands |
||
73 | * eg ',' |
||
74 | */ |
||
75 | private $thousands; |
||
76 | |||
77 | /** |
||
78 | * The number of fractional divisions of a currency's main unit |
||
79 | * Can be used to determine the number of decimal places used. |
||
80 | * Because |
||
81 | * subunits = pow( 10, decimal places ) |
||
82 | * then |
||
83 | * decimal places = log( subunits ) |
||
84 | * except that a result of 1 means there are zero decimal places |
||
85 | * |
||
86 | * @var int |
||
87 | */ |
||
88 | private $subunits; |
||
89 | |||
90 | |||
91 | |||
92 | /** |
||
93 | * Currency constructor. |
||
94 | * |
||
95 | * @param string $code |
||
96 | * @param Label $label |
||
97 | * @param string $sign |
||
98 | * @param bool $sign_b4 |
||
99 | * @param int $decimal_places the number of decimal places to use when DISPLAYING the currency |
||
100 | * @param string $decimal_mark |
||
101 | * @param string $thousands |
||
102 | * @param int $subunits number of fractional divisions of a currency's main unit |
||
103 | */ |
||
104 | public function __construct( |
||
105 | $code, |
||
106 | Label $label, |
||
107 | $sign, |
||
108 | $sign_b4, |
||
109 | $decimal_places, |
||
110 | $decimal_mark, |
||
111 | $thousands, |
||
112 | $subunits |
||
113 | ) { |
||
114 | $this->code = $code; |
||
115 | $this->label = $label; |
||
116 | $this->sign = $sign; |
||
117 | $this->sign_b4 = $sign_b4; |
||
118 | $this->decimal_places = $decimal_places; |
||
119 | $this->decimal_mark = $decimal_mark; |
||
120 | $this->thousands = $thousands; |
||
121 | $this->subunits = $subunits; |
||
122 | } |
||
123 | |||
124 | |||
125 | |||
126 | /** |
||
127 | * returns true if this currency is the same as the supplied currency |
||
128 | * |
||
129 | * @param Currency $other |
||
130 | * @return bool |
||
131 | */ |
||
132 | public function equals(Currency $other) |
||
136 | |||
137 | |||
138 | |||
139 | /** |
||
140 | * @return string |
||
141 | */ |
||
142 | public function code() |
||
146 | |||
147 | |||
148 | |||
149 | /** |
||
150 | * @return string |
||
151 | */ |
||
152 | public function name() |
||
156 | |||
157 | |||
158 | |||
159 | /** |
||
160 | * @return string |
||
161 | */ |
||
162 | public function plural() |
||
166 | |||
167 | |||
168 | |||
169 | /** |
||
170 | * @return string |
||
171 | */ |
||
172 | public function sign() |
||
176 | |||
177 | |||
178 | |||
179 | /** |
||
180 | * @return bool |
||
181 | */ |
||
182 | public function signB4() |
||
186 | |||
187 | |||
188 | |||
189 | /** |
||
190 | * @return int |
||
191 | */ |
||
192 | public function decimalPlaces() |
||
196 | |||
197 | |||
198 | |||
199 | /** |
||
200 | * @return string |
||
201 | */ |
||
202 | public function decimalMark() |
||
206 | |||
207 | |||
208 | |||
209 | /** |
||
210 | * @return string |
||
211 | */ |
||
212 | public function thousands() |
||
216 | |||
217 | |||
218 | |||
219 | /** |
||
220 | * The difference between currency units and subunits |
||
221 | * is 10-to-the-power-of-this. |
||
222 | * DecimalMark is used for display, this is used for calculations |
||
223 | * @return int |
||
224 | */ |
||
225 | public function subunits() |
||
226 | { |
||
227 | return $this->subunits; |
||
228 | } |
||
229 | |||
230 | |||
231 | |||
232 | /** |
||
233 | * @return string |
||
234 | */ |
||
235 | public function __toString() |
||
239 | |||
240 | |||
241 | |||
242 | } |
||
243 | // End of file Currency.php |
||
245 |