2018-02-11 11:16:32 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Support\Units;
|
2018-02-21 12:33:09 +08:00
|
|
|
|
2019-07-16 03:44:31 +08:00
|
|
|
use App\Contracts\Unit;
|
2018-04-08 09:52:12 +08:00
|
|
|
use PhpUnitsOfMeasure\PhysicalQuantity\Mass as MassUnit;
|
2018-02-11 11:16:32 +08:00
|
|
|
|
2018-04-08 09:52:12 +08:00
|
|
|
class Mass extends Unit
|
2018-02-11 11:16:32 +08:00
|
|
|
{
|
2022-03-14 23:45:18 +08:00
|
|
|
public array $responseUnits = [
|
2019-07-16 03:14:40 +08:00
|
|
|
'kg',
|
|
|
|
'lbs',
|
|
|
|
];
|
|
|
|
|
2018-02-11 11:16:32 +08:00
|
|
|
/**
|
2018-04-08 09:52:12 +08:00
|
|
|
* @param float $value
|
|
|
|
* @param string $unit
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
2018-04-08 09:52:12 +08:00
|
|
|
* @throws \PhpUnitsOfMeasure\Exception\NonNumericValue
|
|
|
|
* @throws \PhpUnitsOfMeasure\Exception\NonStringUnitName
|
2018-02-11 11:16:32 +08:00
|
|
|
*/
|
2019-09-20 21:05:09 +08:00
|
|
|
public function __construct($value, string $unit)
|
2018-02-11 11:16:32 +08:00
|
|
|
{
|
2019-09-20 21:05:09 +08:00
|
|
|
if (empty($value)) {
|
|
|
|
$value = 0;
|
|
|
|
}
|
|
|
|
|
2022-03-14 23:45:18 +08:00
|
|
|
$this->localUnit = setting('units.weight');
|
|
|
|
$this->internalUnit = config('phpvms.internal_units.mass');
|
|
|
|
|
|
|
|
if ($value instanceof self) {
|
|
|
|
$value->toUnit($unit);
|
|
|
|
$this->instance = $value->instance;
|
|
|
|
} else {
|
|
|
|
$this->instance = new MassUnit($value, $unit);
|
|
|
|
}
|
2018-02-11 11:16:32 +08:00
|
|
|
}
|
|
|
|
}
|