phpvms/app/Support/Units/Velocity.php

52 lines
1.0 KiB
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 Velocity
* @package App\Support\Units
*/
class Velocity extends \PhpUnitsOfMeasure\PhysicalQuantity\Velocity implements Arrayable
2018-02-11 11:16:32 +08:00
{
/**
* @return string
*/
public function __toString()
{
$unit = setting('general.speed_unit');
$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()
{
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 [
'knots' => round($this->toUnit('knots'), 2),
2018-02-11 11:16:32 +08:00
'km/h' => round($this->toUnit('km/h'), 2),
];
}
/**
* Get the instance as an array.
*/
public function toArray()
{
return round($this->toUnit(
config('phpvms.internal_units.velocity')
), 2);
}
2018-02-11 11:16:32 +08:00
}