1 | <?php namespace Arcanedev\Currencies\Entities; |
||
13 | class Rate implements RateContract, Arrayable, Jsonable |
||
14 | { |
||
15 | /* ------------------------------------------------------------------------------------------------ |
||
16 | | Properties |
||
17 | | ------------------------------------------------------------------------------------------------ |
||
18 | */ |
||
19 | /** |
||
20 | * @var string |
||
21 | */ |
||
22 | protected $from; |
||
23 | |||
24 | /** |
||
25 | * @var string |
||
26 | */ |
||
27 | protected $to; |
||
28 | |||
29 | /** |
||
30 | * @var double |
||
31 | */ |
||
32 | protected $ratio; |
||
33 | |||
34 | /* ------------------------------------------------------------------------------------------------ |
||
35 | | Constructor |
||
36 | | ------------------------------------------------------------------------------------------------ |
||
37 | */ |
||
38 | /** |
||
39 | * Rate constructor. |
||
40 | * |
||
41 | * @param string $from |
||
42 | * @param string $to |
||
43 | * @param double $ratio |
||
44 | */ |
||
45 | 96 | public function __construct($from, $to, $ratio) |
|
51 | |||
52 | /* ------------------------------------------------------------------------------------------------ |
||
53 | | Getters & Setters |
||
54 | | ------------------------------------------------------------------------------------------------ |
||
55 | */ |
||
56 | /** |
||
57 | * Get the `from` currency iso. |
||
58 | * |
||
59 | * @return string |
||
60 | */ |
||
61 | 60 | public function from() |
|
65 | |||
66 | /** |
||
67 | * Get the `from` currency. |
||
68 | * |
||
69 | * @return \Arcanedev\Currencies\Entities\Currency |
||
70 | */ |
||
71 | 12 | public function getFromCurrency() |
|
75 | |||
76 | /** |
||
77 | * Get the `to` currency iso. |
||
78 | * |
||
79 | * @return string |
||
80 | */ |
||
81 | 72 | public function to() |
|
85 | |||
86 | /** |
||
87 | * Get the `to` currency. |
||
88 | * |
||
89 | * @return \Arcanedev\Currencies\Entities\Currency |
||
90 | */ |
||
91 | 12 | public function getToCurrency() |
|
95 | |||
96 | /** |
||
97 | * Get the rate ratio. |
||
98 | * |
||
99 | * @return float |
||
100 | */ |
||
101 | 72 | public function ratio() |
|
105 | |||
106 | /* ------------------------------------------------------------------------------------------------ |
||
107 | | Main Functions |
||
108 | | ------------------------------------------------------------------------------------------------ |
||
109 | */ |
||
110 | /** |
||
111 | * Make a rate instance. |
||
112 | * |
||
113 | * @param string $from |
||
114 | * @param string $to |
||
115 | * @param double $ratio |
||
116 | * |
||
117 | * @return self |
||
118 | */ |
||
119 | 84 | public static function make($from, $to, $ratio) |
|
123 | |||
124 | /** |
||
125 | * Convert the amount. |
||
126 | * |
||
127 | * @param double|int $amount |
||
128 | * |
||
129 | * @return double|int |
||
130 | */ |
||
131 | 12 | public function convert($amount) |
|
135 | |||
136 | /** |
||
137 | * Get the instance as an array. |
||
138 | * |
||
139 | * @return array |
||
140 | */ |
||
141 | 24 | public function toArray() |
|
142 | { |
||
143 | return [ |
||
144 | 24 | 'from' => $this->from(), |
|
145 | 24 | 'to' => $this->to(), |
|
146 | 24 | 'ratio' => $this->ratio(), |
|
147 | 18 | ]; |
|
148 | } |
||
149 | |||
150 | /** |
||
151 | * Convert the object to its JSON representation. |
||
152 | * |
||
153 | * @param int $options |
||
154 | * @return string |
||
155 | */ |
||
156 | 12 | public function toJson($options = 0) |
|
160 | } |
||
161 |