phpvms/app/Support/Units/Altitude.php

46 lines
943 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
/**
* Wrap the converter class
* @package App\Support\Units
*/
class Altitude extends \PhpUnitsOfMeasure\PhysicalQuantity\Length implements Arrayable
2018-02-11 11:16:32 +08:00
{
/**
* The unit that this is stored as
*/
public const STORAGE_UNIT = 'feet';
/**
* @return string
*/
public function __toString()
{
$unit = setting('general.altitude_unit');
$value = $this->toUnit($unit);
return (string) round($value, 2);
}
/**
* For the HTTP Resource call
*/
public function toObject()
2018-02-11 11:16:32 +08:00
{
return [
'ft' => round($this->toUnit('feet'), 2),
'm' => round($this->toUnit('meters') / 1000, 2),
];
}
/**
* Get the instance as an array.
*/
public function toArray()
{
return round($this->toUnit(self::STORAGE_UNIT), 2);
}
2018-02-11 11:16:32 +08:00
}