2018-02-11 11:16:32 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Support\Units;
|
2018-02-11 12:04:30 +08:00
|
|
|
use Illuminate\Contracts\Support\Arrayable;
|
2018-02-11 11:16:32 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class Mass
|
|
|
|
* @package App\Support\Units
|
|
|
|
*/
|
2018-02-11 12:04:30 +08:00
|
|
|
class Mass extends \PhpUnitsOfMeasure\PhysicalQuantity\Mass implements Arrayable
|
2018-02-11 11:16:32 +08:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function __toString()
|
|
|
|
{
|
|
|
|
$unit = setting('general.weight_unit');
|
|
|
|
$value = $this->toUnit($unit);
|
2018-02-11 12:04:30 +08:00
|
|
|
return (string) round($value, 2);
|
2018-02-11 11:16:32 +08:00
|
|
|
}
|
|
|
|
|
2018-02-21 05:32:49 +08:00
|
|
|
/**
|
|
|
|
* Return value in native unit as integer
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function toNumber()
|
|
|
|
{
|
|
|
|
return $this->toArray();
|
|
|
|
}
|
|
|
|
|
2018-02-11 11:16:32 +08:00
|
|
|
/**
|
|
|
|
* For the HTTP Resource call
|
|
|
|
*/
|
2018-02-11 12:04:30 +08:00
|
|
|
public function toObject()
|
2018-02-11 11:16:32 +08:00
|
|
|
{
|
|
|
|
return [
|
|
|
|
'kg' => round($this->toUnit('kg'), 2),
|
2018-02-11 12:04:30 +08:00
|
|
|
'lbs' => round($this->toUnit('lbs'), 2),
|
2018-02-11 11:16:32 +08:00
|
|
|
];
|
|
|
|
}
|
2018-02-11 12:04:30 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the instance as an array.
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function toArray()
|
|
|
|
{
|
2018-02-12 10:19:02 +08:00
|
|
|
return round($this->toUnit(
|
|
|
|
config('phpvms.internal_units.mass')
|
|
|
|
), 2);
|
2018-02-11 12:04:30 +08:00
|
|
|
}
|
2018-02-11 11:16:32 +08:00
|
|
|
}
|