1 | <?php namespace Arcanedev\Currencies\Entities; |
||
29 | class Currency implements CurrencyContract, Arrayable, ArrayAccess, Jsonable |
||
30 | { |
||
31 | /* ------------------------------------------------------------------------------------------------ |
||
32 | | Properties |
||
33 | | ------------------------------------------------------------------------------------------------ |
||
34 | */ |
||
35 | /** |
||
36 | * Currency attributes. |
||
37 | * |
||
38 | * @var array |
||
39 | */ |
||
40 | protected $attributes = []; |
||
41 | |||
42 | /* ------------------------------------------------------------------------------------------------ |
||
43 | | Constructor |
||
44 | | ------------------------------------------------------------------------------------------------ |
||
45 | */ |
||
46 | /** |
||
47 | * Currency constructor. |
||
48 | * |
||
49 | * @param string $key |
||
50 | * @param array $attributes |
||
51 | */ |
||
52 | 384 | public function __construct($key, array $attributes) |
|
58 | |||
59 | /* ------------------------------------------------------------------------------------------------ |
||
60 | | Getters & Setters |
||
61 | | ------------------------------------------------------------------------------------------------ |
||
62 | */ |
||
63 | /** |
||
64 | * Get an attribute. |
||
65 | * |
||
66 | * @param string $name |
||
67 | * |
||
68 | * @return mixed |
||
69 | */ |
||
70 | 384 | public function __get($name) |
|
74 | |||
75 | /** |
||
76 | * Get required attributes. |
||
77 | * |
||
78 | * @return array |
||
79 | */ |
||
80 | 384 | protected function getRequiredAttributes() |
|
87 | |||
88 | /* ------------------------------------------------------------------------------------------------ |
||
89 | | Main Functions |
||
90 | | ------------------------------------------------------------------------------------------------ |
||
91 | */ |
||
92 | /** |
||
93 | * Make a currency instance. |
||
94 | * |
||
95 | * @param string $key |
||
96 | * @param array $attributes |
||
97 | * |
||
98 | * @return self |
||
99 | */ |
||
100 | 384 | public static function make($key, array $attributes) |
|
104 | |||
105 | /** |
||
106 | * Format the currency amount. |
||
107 | * |
||
108 | * @param int $amount - Amount in cents |
||
109 | * @param int $decimals |
||
110 | * |
||
111 | * @return string |
||
112 | */ |
||
113 | 12 | public function format($amount, $decimals = 2) |
|
126 | |||
127 | /** |
||
128 | * Get the instance as an array. |
||
129 | * |
||
130 | * @return array |
||
131 | */ |
||
132 | 24 | public function toArray() |
|
136 | |||
137 | /** |
||
138 | * Convert the object to its JSON representation. |
||
139 | * |
||
140 | * @param int $options |
||
141 | * |
||
142 | * @return string |
||
143 | */ |
||
144 | 12 | public function toJson($options = 0) |
|
148 | |||
149 | /* ------------------------------------------------------------------------------------------------ |
||
150 | | Check Functions |
||
151 | | ------------------------------------------------------------------------------------------------ |
||
152 | */ |
||
153 | /** |
||
154 | * Check the required attributes. |
||
155 | * |
||
156 | * @param array $attributes |
||
157 | * |
||
158 | * @throws \Arcanedev\Currencies\Exceptions\InvalidCurrencyArgumentException |
||
159 | */ |
||
160 | 384 | private function checkRequiredAttributes(array $attributes) |
|
170 | |||
171 | /** |
||
172 | * Whether a offset exists |
||
173 | * @link http://php.net/manual/en/arrayaccess.offsetexists.php |
||
174 | * |
||
175 | * @param string $offset |
||
176 | * |
||
177 | * @return bool |
||
178 | */ |
||
179 | 12 | public function offsetExists($offset) |
|
183 | |||
184 | /** |
||
185 | * Offset to retrieve |
||
186 | * @link http://php.net/manual/en/arrayaccess.offsetget.php |
||
187 | * |
||
188 | * @param string $offset |
||
189 | * |
||
190 | * @return mixed |
||
191 | */ |
||
192 | 12 | public function offsetGet($offset) |
|
196 | |||
197 | /** |
||
198 | * Offset to set |
||
199 | * @link http://php.net/manual/en/arrayaccess.offsetset.php |
||
200 | * |
||
201 | * @param string $offset |
||
202 | * @param mixed $value |
||
203 | */ |
||
204 | public function offsetSet($offset, $value) { /** DO NOTHING **/ } |
||
205 | |||
206 | /** |
||
207 | * Offset to unset |
||
208 | * @link http://php.net/manual/en/arrayaccess.offsetunset.php |
||
209 | * |
||
210 | * @param string $offset |
||
211 | */ |
||
212 | public function offsetUnset($offset) { /** DO NOTHING **/ } |
||
213 | } |
||
214 |