phpvms/app/Support/Units/Distance.php

32 lines
856 B
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 App\Interfaces\Unit;
use PhpUnitsOfMeasure\PhysicalQuantity\Length;
2018-02-11 11:16:32 +08:00
class Distance extends Unit
2018-02-11 11:16:32 +08:00
{
/**
* Distance constructor.
2018-08-27 00:40:04 +08:00
*
* @param float $value
* @param string $unit
2018-08-27 00:40:04 +08:00
*
* @throws \PhpUnitsOfMeasure\Exception\NonNumericValue
* @throws \PhpUnitsOfMeasure\Exception\NonStringUnitName
2018-02-11 11:16:32 +08:00
*/
public function __construct(float $value, string $unit)
2018-02-11 11:16:32 +08:00
{
$this->unit = setting('units.distance');
$this->instance = new Length($value, $unit);
$this->units = [
'mi' => round($this->instance->toUnit('miles'), 2),
'nmi' => round($this->instance->toUnit('nmi'), 2),
'm' => round($this->instance->toUnit('meters'), 2),
'km' => round($this->instance->toUnit('meters') / 1000, 2),
2018-02-11 11:16:32 +08:00
];
}
}