1 | <?php namespace Arcanedev\Units\Measures; |
||
14 | class Weight extends UnitMeasure implements WeightContract |
||
15 | { |
||
16 | /* ------------------------------------------------------------------------------------------------ |
||
17 | | Traits |
||
18 | | ------------------------------------------------------------------------------------------------ |
||
19 | */ |
||
20 | use Calculatable; |
||
21 | |||
22 | /* ------------------------------------------------------------------------------------------------ |
||
23 | | Constructor |
||
24 | | ------------------------------------------------------------------------------------------------ |
||
25 | */ |
||
26 | /** |
||
27 | * Weight constructor. |
||
28 | * |
||
29 | * @param float|int $value |
||
30 | * @param string $unit |
||
31 | * @param array $options |
||
32 | */ |
||
33 | 168 | public function __construct($value = 0, $unit = self::KG, array $options = []) |
|
44 | |||
45 | /* ------------------------------------------------------------------------------------------------ |
||
46 | | Getters & Setters |
||
47 | | ------------------------------------------------------------------------------------------------ |
||
48 | */ |
||
49 | /** |
||
50 | * Get the symbol's names. |
||
51 | * |
||
52 | * @return array |
||
53 | */ |
||
54 | 8 | public static function names() |
|
63 | |||
64 | /** |
||
65 | * Get the symbol name. |
||
66 | * |
||
67 | * @param string $unit |
||
68 | * |
||
69 | * @return string |
||
70 | */ |
||
71 | 8 | public static function getSymbolName($unit) |
|
77 | |||
78 | /* ------------------------------------------------------------------------------------------------ |
||
79 | | Main Functions |
||
80 | | ------------------------------------------------------------------------------------------------ |
||
81 | */ |
||
82 | /** |
||
83 | * Make a weight instance. |
||
84 | * |
||
85 | * @param float|int $value |
||
86 | * @param string $unit |
||
87 | * @param array $options |
||
88 | * |
||
89 | * @return \Arcanedev\Units\Contracts\Weight |
||
90 | */ |
||
91 | 64 | public static function make($value = 0, $unit = self::KG, array $options = []) |
|
95 | |||
96 | /** |
||
97 | * Convert the weight to the given unit. |
||
98 | * |
||
99 | * @param string $to |
||
100 | * |
||
101 | * @return \Arcanedev\Units\Contracts\Weight |
||
102 | */ |
||
103 | 64 | public function to($to) |
|
111 | |||
112 | /** |
||
113 | * Convert the weight. |
||
114 | * |
||
115 | * @param string $from |
||
116 | * @param string $to |
||
117 | * @param float|int $value |
||
118 | * |
||
119 | * @return float|int |
||
120 | */ |
||
121 | 16 | public static function convert($from, $to, $value) |
|
125 | |||
126 | /* ------------------------------------------------------------------------------------------------ |
||
127 | | Calculation Functions |
||
128 | | ------------------------------------------------------------------------------------------------ |
||
129 | */ |
||
130 | /** |
||
131 | * Add the weight. |
||
132 | * |
||
133 | * @param double|float|integer $value |
||
134 | * @param string $unit |
||
135 | * |
||
136 | * @return \Arcanedev\Units\Contracts\Weight |
||
137 | */ |
||
138 | 16 | public function addWeight($value, $unit = self::KG) |
|
144 | |||
145 | /** |
||
146 | * Add the weight instance. |
||
147 | * |
||
148 | * @param \Arcanedev\Units\Contracts\Weight $weight |
||
149 | * |
||
150 | * @return \Arcanedev\Units\Contracts\Weight |
||
151 | */ |
||
152 | 32 | public function add(WeightContract $weight) |
|
160 | |||
161 | /** |
||
162 | * Sub the weight. |
||
163 | * |
||
164 | * @param float|int $value |
||
165 | * @param string $unit |
||
166 | * |
||
167 | * @return \Arcanedev\Units\Contracts\Weight |
||
168 | */ |
||
169 | 16 | public function subWeight($value, $unit = self::KG) |
|
175 | |||
176 | /** |
||
177 | * Sub the weight instance. |
||
178 | * |
||
179 | * @param \Arcanedev\Units\Contracts\Weight $weight |
||
180 | * |
||
181 | * @return \Arcanedev\Units\Contracts\Weight |
||
182 | */ |
||
183 | 16 | public function sub(WeightContract $weight) |
|
191 | |||
192 | /** |
||
193 | * Multiply weight by the given number. |
||
194 | * |
||
195 | * @param float|int $number |
||
196 | * |
||
197 | * @return \Arcanedev\Units\Contracts\Weight |
||
198 | */ |
||
199 | 16 | public function multiply($number) |
|
205 | |||
206 | /** |
||
207 | * Divide weight by the given number. |
||
208 | * |
||
209 | * @param float|int $number |
||
210 | * |
||
211 | * @return \Arcanedev\Units\Contracts\Weight |
||
212 | */ |
||
213 | 16 | public function divide($number) |
|
219 | |||
220 | /* ------------------------------------------------------------------------------------------------ |
||
221 | | Other Functions |
||
222 | | ------------------------------------------------------------------------------------------------ |
||
223 | */ |
||
224 | /** |
||
225 | * Get the weight convert ratio. |
||
226 | * |
||
227 | * @param string $to |
||
228 | * @param string $from |
||
229 | * |
||
230 | * @return double|float|integer |
||
231 | */ |
||
232 | 16 | protected static function getRatio($to, $from) |
|
243 | |||
244 | /** |
||
245 | * Get all the weight ratios. |
||
246 | * |
||
247 | * @return array |
||
248 | */ |
||
249 | 16 | protected static function getRatios() |
|
262 | } |
||
263 |