1 | <?php |
||
23 | class MoneyFactory |
||
24 | { |
||
25 | |||
26 | /** |
||
27 | * @var CurrencyFactory $currency_factory |
||
28 | */ |
||
29 | protected $currency_factory; |
||
30 | |||
31 | /** |
||
32 | * @var Calculator $calculator |
||
33 | */ |
||
34 | protected $calculator; |
||
35 | |||
36 | /** |
||
37 | * @var MoneyFormatter[] $formatters |
||
38 | */ |
||
39 | protected $formatters; |
||
40 | |||
41 | |||
42 | /** |
||
43 | * CreateMoney constructor. |
||
44 | * |
||
45 | * @param CurrencyFactory $currency_factory |
||
46 | * @param Calculator $calculator |
||
47 | * @param MoneyFormatter[] $formatters |
||
48 | */ |
||
49 | public function __construct( |
||
58 | |||
59 | |||
60 | |||
61 | /** |
||
62 | * factory method that returns a Money object using amount specified in the currency's subunits |
||
63 | * example: for $12.50 USD use CreateMoney::fromSubUnits(1250, 'USD') |
||
64 | * |
||
65 | * @param int $subunits_amount money amount IN THE SUBUNITS FOR THE CURRENCY ie: cents |
||
66 | * example: $12.50 USD would equate to a subunits amount of 1250 |
||
67 | * @param string $currency_code |
||
68 | * @return Money |
||
69 | * @throws EE_Error |
||
70 | * @throws InvalidArgumentException |
||
71 | * @throws InvalidDataTypeException |
||
72 | * @throws InvalidInterfaceException |
||
73 | */ |
||
74 | public function createFromSubUnits($subunits_amount, $currency_code = '') |
||
85 | |||
86 | |||
87 | |||
88 | /** |
||
89 | * factory method that returns a Money object using the currency corresponding to the site's country |
||
90 | * example: CreateMoney::forSite(12.5) |
||
91 | * |
||
92 | * @param float|int|string $amount money amount IN THE STANDARD UNIT FOR THE CURRENCY ie: dollars, Euros, etc |
||
93 | * example: $12.5 USD would equate to a standard amount of 12.50 |
||
94 | * @return Money |
||
95 | * @throws EE_Error |
||
96 | * @throws InvalidArgumentException |
||
97 | * @throws InvalidDataTypeException |
||
98 | * @throws InvalidInterfaceException |
||
99 | */ |
||
100 | public function createForSite($amount) |
||
109 | |||
110 | |||
111 | |||
112 | /** |
||
113 | * factory method that returns a Money object using the currency as specified by the supplied ISO country code |
||
114 | * example: CreateMoney::forCountry(12.5,'US') |
||
115 | * |
||
116 | * @param float|int|string $amount money amount IN THE STANDARD UNIT FOR THE CURRENCY ie: dollars, Euros, etc |
||
117 | * example: $12.5 USD would equate to a value amount of 12.50 |
||
118 | * @param string $CNT_ISO |
||
119 | * @return Money |
||
120 | * @throws EE_Error |
||
121 | * @throws InvalidArgumentException |
||
122 | * @throws InvalidDataTypeException |
||
123 | * @throws InvalidInterfaceException |
||
124 | */ |
||
125 | public function createForCountry($amount, $CNT_ISO) |
||
134 | |||
135 | |||
136 | |||
137 | /** |
||
138 | * factory method that returns a Money object using the currency as specified by the supplied currency code |
||
139 | * example: CreateMoney::forCurrency(12.5, 'USD') |
||
140 | * |
||
141 | * @param float|int|string $amount money amount IN THE STANDARD UNIT FOR THE CURRENCY ie: dollars, Euros, etc |
||
142 | * example: $12.5 USD would equate to a value amount of 12.50 |
||
143 | * @param string $currency_code |
||
144 | * @return Money |
||
145 | * @throws EE_Error |
||
146 | * @throws InvalidArgumentException |
||
147 | * @throws InvalidDataTypeException |
||
148 | * @throws InvalidInterfaceException |
||
149 | */ |
||
150 | public function createForCurrency($amount, $currency_code) |
||
159 | |||
160 | |||
161 | |||
162 | |||
163 | /** |
||
164 | * @return Calculator |
||
165 | */ |
||
166 | public function calculator() |
||
171 | |||
172 | |||
173 | |||
174 | /** |
||
175 | * loops through a filterable array of Calculator services |
||
176 | * and selects the first one that is supported by the current server |
||
177 | */ |
||
178 | protected function initializeCalculators() |
||
200 | |||
201 | |||
202 | |||
203 | /** |
||
204 | * @return MoneyFormatter[] |
||
205 | */ |
||
206 | public function formatters() |
||
211 | |||
212 | |||
213 | |||
214 | /** |
||
215 | * initializes a filterable array of MoneyFormatter services |
||
216 | */ |
||
217 | protected function initializeFormatters() |
||
233 | |||
234 | |||
235 | } |
||
236 | // End of file CreateMoney.php |
||
238 |