|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @category Brownie/ExchangeRate |
|
4
|
|
|
* @author Brownie <[email protected]> |
|
5
|
|
|
* @license https://opensource.org/licenses/MIT |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace Brownie\ExchangeRate\Model; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* A exchange rate model. |
|
12
|
|
|
*/ |
|
13
|
|
|
class ExchangeRate |
|
14
|
|
|
{ |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Base currency. |
|
18
|
|
|
* |
|
19
|
|
|
* @var string |
|
20
|
|
|
*/ |
|
21
|
|
|
private $baseCode; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Currency code. |
|
25
|
|
|
* |
|
26
|
|
|
* @var string |
|
27
|
|
|
*/ |
|
28
|
|
|
private $currencyCode; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Currency rate. |
|
32
|
|
|
* Indicates how much the base currency is in the current one. |
|
33
|
|
|
* |
|
34
|
|
|
* @var float |
|
35
|
|
|
*/ |
|
36
|
|
|
private $rate; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Sets the input values. |
|
40
|
|
|
* |
|
41
|
|
|
* @param string $baseCode Base currency. |
|
42
|
|
|
* @param string $currencyCode Currency code. |
|
43
|
|
|
* @param float $rate Currency rate. |
|
44
|
|
|
*/ |
|
45
|
7 |
|
public function __construct($baseCode, $currencyCode, $rate) |
|
46
|
|
|
{ |
|
47
|
|
|
$this |
|
48
|
7 |
|
->setBaseCode($baseCode) |
|
49
|
7 |
|
->setCurrencyCode($currencyCode) |
|
50
|
7 |
|
->setRate($rate); |
|
51
|
7 |
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Sets base currency. |
|
55
|
|
|
* Returns the current object. |
|
56
|
|
|
* |
|
57
|
|
|
* @param string $baseCode Base currency. |
|
58
|
|
|
* |
|
59
|
|
|
* @return self |
|
60
|
|
|
*/ |
|
61
|
7 |
|
private function setBaseCode($baseCode) |
|
62
|
|
|
{ |
|
63
|
7 |
|
$this->baseCode = $baseCode; |
|
64
|
7 |
|
return $this; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Sets currency code. |
|
69
|
|
|
* Returns the current object. |
|
70
|
|
|
* |
|
71
|
|
|
* @param string $currencyCode Currency code. |
|
72
|
|
|
* |
|
73
|
|
|
* @return self |
|
74
|
|
|
*/ |
|
75
|
7 |
|
private function setCurrencyCode($currencyCode) |
|
76
|
|
|
{ |
|
77
|
7 |
|
$this->currencyCode = $currencyCode; |
|
78
|
7 |
|
return $this; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Sets currency rate. |
|
83
|
|
|
* Returns the current object. |
|
84
|
|
|
* |
|
85
|
|
|
* @param float $rate Currency rate. |
|
86
|
|
|
* |
|
87
|
|
|
* @return self |
|
88
|
|
|
*/ |
|
89
|
7 |
|
private function setRate($rate) |
|
90
|
|
|
{ |
|
91
|
7 |
|
$this->rate = $rate; |
|
92
|
7 |
|
return $this; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* Gets base currency. |
|
97
|
|
|
* |
|
98
|
|
|
* @return string |
|
99
|
|
|
*/ |
|
100
|
7 |
|
public function getBaseCode() |
|
101
|
|
|
{ |
|
102
|
7 |
|
return $this->baseCode; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* Gets currency code. |
|
107
|
|
|
* |
|
108
|
|
|
* @return string |
|
109
|
|
|
*/ |
|
110
|
7 |
|
public function getCurrencyCode() |
|
111
|
|
|
{ |
|
112
|
7 |
|
return $this->currencyCode; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* Gets currency rate. |
|
117
|
|
|
* |
|
118
|
|
|
* @return float |
|
119
|
|
|
*/ |
|
120
|
7 |
|
public function getRate() |
|
121
|
|
|
{ |
|
122
|
7 |
|
return $this->rate; |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* Gets currency exchange data as an associative array. |
|
127
|
|
|
* |
|
128
|
|
|
* @return array |
|
129
|
|
|
*/ |
|
130
|
7 |
|
public function toArray() |
|
131
|
|
|
{ |
|
132
|
|
|
return [ |
|
133
|
7 |
|
'baseCode' => $this->getBaseCode(), |
|
134
|
7 |
|
'currencyCode' => $this->getCurrencyCode(), |
|
135
|
7 |
|
'rate' => $this->getRate() |
|
136
|
|
|
]; |
|
137
|
|
|
} |
|
138
|
|
|
} |
|
139
|
|
|
|