phpvms/app/Support/Units/Volume.php

54 lines
1.0 KiB
PHP
Raw Normal View History

2018-02-11 11:16:32 +08:00
<?php
namespace App\Support\Units;
2018-02-21 12:33:09 +08:00
use Illuminate\Contracts\Support\Arrayable;
2018-02-11 11:16:32 +08:00
/**
* Wrap the converter class
* @package App\Support\Units
*/
class Volume extends \PhpUnitsOfMeasure\PhysicalQuantity\Volume implements Arrayable
2018-02-11 11:16:32 +08:00
{
/**
* @return string
*/
public function __toString()
{
$unit = setting('units.volume');
2018-02-11 11:16:32 +08:00
$value = $this->toUnit($unit);
2018-02-11 11:16:32 +08:00
return (string) round($value, 2);
}
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
*/
public function toObject()
2018-02-11 11:16:32 +08:00
{
return [
'gal' => round($this->toUnit('gal'), 2),
'liters' => round($this->toUnit('liters'), 2),
2018-02-11 11:16:32 +08:00
];
}
/**
* Get the instance as an array.
*/
public function toArray()
{
return round($this->toUnit(
config('phpvms.internal_units.volume')
), 2);
}
2018-02-11 11:16:32 +08:00
}