2018-02-11 11:16:32 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Support\Units;
|
2018-02-21 12:33:09 +08:00
|
|
|
|
2018-02-11 12:04:30 +08:00
|
|
|
use Illuminate\Contracts\Support\Arrayable;
|
2018-02-11 11:16:32 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class Velocity
|
|
|
|
* @package App\Support\Units
|
|
|
|
*/
|
2018-02-11 12:04:30 +08:00
|
|
|
class Velocity extends \PhpUnitsOfMeasure\PhysicalQuantity\Velocity implements Arrayable
|
2018-02-11 11:16:32 +08:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function __toString()
|
|
|
|
{
|
2018-02-27 10:23:48 +08:00
|
|
|
$unit = setting('units.speed');
|
2018-02-11 11:16:32 +08:00
|
|
|
$value = $this->toUnit($unit);
|
2018-03-20 09:50:40 +08:00
|
|
|
|
2018-02-11 11:16:32 +08:00
|
|
|
return (string) round($value, 2);
|
|
|
|
}
|
|
|
|
|
2018-02-21 04:07:33 +08:00
|
|
|
/**
|
|
|
|
* 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();
|
|
|
|
}
|
|
|
|
|
2018-02-11 11:16:32 +08:00
|
|
|
/**
|
|
|
|
* For the HTTP Resource call
|
|
|
|
*/
|
2018-02-11 12:04:30 +08:00
|
|
|
public function toObject()
|
2018-02-11 11:16:32 +08:00
|
|
|
{
|
|
|
|
return [
|
2018-02-12 10:19:02 +08:00
|
|
|
'knots' => round($this->toUnit('knots'), 2),
|
2018-03-20 09:50:40 +08:00
|
|
|
'km/h' => round($this->toUnit('km/h'), 2),
|
2018-02-11 11:16:32 +08:00
|
|
|
];
|
|
|
|
}
|
2018-02-11 12:04:30 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the instance as an array.
|
|
|
|
*/
|
|
|
|
public function toArray()
|
|
|
|
{
|
2018-02-12 10:19:02 +08:00
|
|
|
return round($this->toUnit(
|
|
|
|
config('phpvms.internal_units.velocity')
|
|
|
|
), 2);
|
2018-02-11 12:04:30 +08:00
|
|
|
}
|
2018-02-11 11:16:32 +08:00
|
|
|
}
|