phpvms/app/Support/Units/Mass.php

49 lines
963 B
PHP
Raw Normal View History

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