1 | <?php namespace Arcanedev\Currencies\Entities; |
||
28 | class Currency implements CurrencyContract, Arrayable, Jsonable |
||
29 | { |
||
30 | /* ------------------------------------------------------------------------------------------------ |
||
31 | | Properties |
||
32 | | ------------------------------------------------------------------------------------------------ |
||
33 | */ |
||
34 | /** |
||
35 | * Currency attributes. |
||
36 | * |
||
37 | * @var array |
||
38 | */ |
||
39 | protected $attributes = []; |
||
40 | |||
41 | /* ------------------------------------------------------------------------------------------------ |
||
42 | | Constructor |
||
43 | | ------------------------------------------------------------------------------------------------ |
||
44 | */ |
||
45 | /** |
||
46 | * Currency constructor. |
||
47 | * |
||
48 | * @param string $key |
||
49 | * @param array $attributes |
||
50 | */ |
||
51 | 180 | public function __construct($key, array $attributes) |
|
57 | |||
58 | /* ------------------------------------------------------------------------------------------------ |
||
59 | | Getters & Setters |
||
60 | | ------------------------------------------------------------------------------------------------ |
||
61 | */ |
||
62 | /** |
||
63 | * Get an attribute. |
||
64 | * |
||
65 | * @param string $name |
||
66 | * |
||
67 | * @return mixed |
||
68 | */ |
||
69 | 180 | public function __get($name) |
|
73 | |||
74 | /** |
||
75 | * Get required attributes. |
||
76 | * |
||
77 | * @return array |
||
78 | */ |
||
79 | 180 | protected function getRequiredAttributes() |
|
86 | |||
87 | /* ------------------------------------------------------------------------------------------------ |
||
88 | | Main Functions |
||
89 | | ------------------------------------------------------------------------------------------------ |
||
90 | */ |
||
91 | /** |
||
92 | * Make a currency instance. |
||
93 | * |
||
94 | * @param string $key |
||
95 | * @param array $attributes |
||
96 | * |
||
97 | * @return self |
||
98 | */ |
||
99 | 180 | public static function make($key, array $attributes) |
|
103 | |||
104 | /** |
||
105 | * Format the currency amount. |
||
106 | * |
||
107 | * @param int $amount - Amount in cents |
||
108 | * @param int $decimals |
||
109 | * |
||
110 | * @return string |
||
111 | */ |
||
112 | 12 | public function format($amount, $decimals = 2) |
|
125 | |||
126 | /** |
||
127 | * Get the instance as an array. |
||
128 | * |
||
129 | * @return array |
||
130 | */ |
||
131 | 24 | public function toArray() |
|
135 | |||
136 | /** |
||
137 | * Convert the object to its JSON representation. |
||
138 | * |
||
139 | * @param int $options |
||
140 | * |
||
141 | * @return string |
||
142 | */ |
||
143 | 12 | public function toJson($options = 0) |
|
147 | |||
148 | /* ------------------------------------------------------------------------------------------------ |
||
149 | | Check Functions |
||
150 | | ------------------------------------------------------------------------------------------------ |
||
151 | */ |
||
152 | /** |
||
153 | * Check the required attributes. |
||
154 | * |
||
155 | * @param array $attributes |
||
156 | * |
||
157 | * @throws \Arcanedev\Currencies\Exceptions\InvalidCurrencyArgumentException |
||
158 | */ |
||
159 | 180 | private function checkRequiredAttributes(array $attributes) |
|
169 | } |
||
170 |