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