1 | <?php namespace Arcanedev\Units\Bases; |
||
12 | abstract class UnitMeasure |
||
13 | { |
||
14 | /* ------------------------------------------------------------------------------------------------ |
||
15 | | Properties |
||
16 | | ------------------------------------------------------------------------------------------------ |
||
17 | */ |
||
18 | /** |
||
19 | * The unit. |
||
20 | * |
||
21 | * @var string |
||
22 | */ |
||
23 | protected $unit; |
||
24 | |||
25 | /** |
||
26 | * The value. |
||
27 | * |
||
28 | * @var float|int |
||
29 | */ |
||
30 | protected $value; |
||
31 | |||
32 | /** |
||
33 | * The symbols. |
||
34 | * |
||
35 | * @var array |
||
36 | */ |
||
37 | protected $symbols = []; |
||
38 | |||
39 | /** |
||
40 | * The number of decimals to format. |
||
41 | * |
||
42 | * @var int |
||
43 | */ |
||
44 | protected $decimals = 0; |
||
45 | |||
46 | /** |
||
47 | * The decimal separator. |
||
48 | * |
||
49 | * @var string |
||
50 | */ |
||
51 | protected $decimalSeparator = '.'; |
||
52 | |||
53 | /** |
||
54 | * The thousands separator. |
||
55 | * |
||
56 | * @var string |
||
57 | */ |
||
58 | protected $thousandsSeparator = ','; |
||
59 | |||
60 | /* ------------------------------------------------------------------------------------------------ |
||
61 | | Getters & Setters |
||
62 | | ------------------------------------------------------------------------------------------------ |
||
63 | */ |
||
64 | /** |
||
65 | * Get the weight value. |
||
66 | * |
||
67 | * @return float|int |
||
68 | */ |
||
69 | 136 | public function value() |
|
73 | |||
74 | /** |
||
75 | * Set the weight value. |
||
76 | * |
||
77 | * @param float|int $value |
||
78 | * |
||
79 | * @return static |
||
80 | */ |
||
81 | 168 | public function setValue($value) |
|
87 | |||
88 | /** |
||
89 | * Get the default units. |
||
90 | * |
||
91 | * @return array |
||
92 | */ |
||
93 | 168 | public static function units() |
|
100 | |||
101 | /** |
||
102 | * Get the weight unit. |
||
103 | * |
||
104 | * @return string |
||
105 | */ |
||
106 | 80 | public function unit() |
|
110 | |||
111 | /** |
||
112 | * Set the weight unit. |
||
113 | * |
||
114 | * @param string $unit |
||
115 | * |
||
116 | * @return static |
||
117 | */ |
||
118 | 168 | public function setUnit($unit) |
|
126 | |||
127 | /** |
||
128 | * Get the available units. |
||
129 | * |
||
130 | * @return array |
||
131 | */ |
||
132 | 32 | public function symbols() |
|
136 | |||
137 | /** |
||
138 | * Get the symbol. |
||
139 | * |
||
140 | * @return string |
||
141 | */ |
||
142 | 24 | public function symbol() |
|
146 | |||
147 | /** |
||
148 | * Set the unit symbol. |
||
149 | * |
||
150 | * @param string $unit |
||
151 | * @param string $symbol |
||
152 | * |
||
153 | * @return static |
||
154 | */ |
||
155 | 168 | public function setSymbol($unit, $symbol) |
|
163 | |||
164 | /** |
||
165 | * Get the default symbols. |
||
166 | * |
||
167 | * @return array |
||
168 | */ |
||
169 | 168 | protected static function defaultSymbols() |
|
173 | |||
174 | /** |
||
175 | * Set the symbols. |
||
176 | * |
||
177 | * @param array $symbols |
||
178 | * |
||
179 | * @return static |
||
180 | */ |
||
181 | 168 | public function setSymbols(array $symbols) |
|
191 | |||
192 | /** |
||
193 | * Set the format. |
||
194 | * |
||
195 | * @param int $decimals |
||
196 | * @param string $decimalSeparator |
||
197 | * @param string $thousandsSeparator |
||
198 | * |
||
199 | * @return static |
||
200 | */ |
||
201 | 168 | public function setFormat($decimals = 0, $decimalSeparator = ',', $thousandsSeparator = '.') |
|
209 | |||
210 | /* ------------------------------------------------------------------------------------------------ |
||
211 | | Main Functions |
||
212 | | ------------------------------------------------------------------------------------------------ |
||
213 | */ |
||
214 | /** |
||
215 | * Format the weight. |
||
216 | * |
||
217 | * @param int|null $decimals |
||
218 | * @param string|null $decimalSeparator |
||
219 | * @param string|null $thousandsSeparator |
||
220 | * |
||
221 | * @return string |
||
222 | */ |
||
223 | 24 | public function format( |
|
234 | |||
235 | /** |
||
236 | * Format the weight with symbol. |
||
237 | * |
||
238 | * @param int|null $decimals |
||
239 | * @param string|null $decimalSeparator |
||
240 | * @param string|null $thousandsSeparator |
||
241 | * |
||
242 | * @return string |
||
243 | */ |
||
244 | 16 | public function formatWithSymbol( |
|
251 | |||
252 | /** |
||
253 | * Convert object to string. |
||
254 | * |
||
255 | * @return string |
||
256 | */ |
||
257 | 8 | public function __toString() |
|
261 | |||
262 | /* ------------------------------------------------------------------------------------------------ |
||
263 | | Check Functions |
||
264 | | ------------------------------------------------------------------------------------------------ |
||
265 | */ |
||
266 | /** |
||
267 | * Check the weight unit. |
||
268 | * |
||
269 | * @param string $unit |
||
270 | */ |
||
271 | 168 | protected static function checkUnit($unit) |
|
279 | } |
||
280 |