1 | <?php |
||
24 | class CurrencyConverter |
||
25 | { |
||
26 | /** |
||
27 | * @var ProviderInterface |
||
28 | */ |
||
29 | protected $provider; |
||
30 | |||
31 | /** |
||
32 | * @var string Currency ISO Code 4217 |
||
33 | */ |
||
34 | protected $from; |
||
35 | |||
36 | /** |
||
37 | * @var string Currency ISO Code 4217 |
||
38 | */ |
||
39 | protected $to; |
||
40 | |||
41 | /** |
||
42 | * @param ProviderInterface $provider optional parameter |
||
43 | */ |
||
44 | public function __construct(ProviderInterface $provider = null) |
||
48 | |||
49 | /** |
||
50 | * @param ProviderInterface $provider |
||
51 | * @return self |
||
52 | */ |
||
53 | public function setProvider(ProviderInterface $provider) |
||
59 | |||
60 | /** |
||
61 | * The origin currency |
||
62 | * |
||
63 | * @param string $value ISO Code 4217 (example : USD, EUR). See http://fr.wikipedia.org/wiki/ISO_4217 |
||
64 | * @return self |
||
65 | */ |
||
66 | public function from($value) |
||
72 | |||
73 | /** |
||
74 | * |
||
75 | * the currency desired |
||
76 | * |
||
77 | * @param string $value ISO Code 4217 (example : USD, EUR). See http://fr.wikipedia.org/wiki/ISO_4217 |
||
78 | * @return self |
||
79 | */ |
||
80 | public function to($value) |
||
86 | |||
87 | /** |
||
88 | * |
||
89 | * convert a currency from one to another one |
||
90 | * |
||
91 | * eg : $converter->from('EUR')->to('USD')->convert(Number('1')); |
||
92 | * |
||
93 | * @param \Thelia\Math\Number $number |
||
94 | * @return \Thelia\Math\Number |
||
95 | */ |
||
96 | public function convert(Number $number) |
||
111 | |||
112 | /** |
||
113 | * Verify if the conversation can be done. |
||
114 | * |
||
115 | * @throws MissingProviderException thrown if the provider is missing |
||
116 | * @throws \RuntimeException thrown if to or from parameters are missing |
||
117 | */ |
||
118 | private function validate() |
||
128 | |||
129 | /** |
||
130 | * remove from and to configuration. |
||
131 | */ |
||
132 | private function reset() |
||
137 | } |
||
138 |