2018-04-03 11:35:25 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Support\Units;
|
|
|
|
|
2018-04-08 09:52:12 +08:00
|
|
|
use App\Interfaces\Unit;
|
|
|
|
use PhpUnitsOfMeasure\PhysicalQuantity\Temperature as TemperatureUnit;
|
2018-04-03 11:35:25 +08:00
|
|
|
|
|
|
|
/**
|
2018-04-08 09:52:12 +08:00
|
|
|
* Composition for the converter
|
2018-04-03 11:35:25 +08:00
|
|
|
*/
|
2018-04-08 09:52:12 +08:00
|
|
|
class Temperature extends Unit
|
2018-04-03 11:35:25 +08:00
|
|
|
{
|
|
|
|
/**
|
2018-04-08 09:52:12 +08:00
|
|
|
* @param float $value
|
|
|
|
* @param string $unit
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
2018-04-08 09:52:12 +08:00
|
|
|
* @throws \PhpUnitsOfMeasure\Exception\NonNumericValue
|
|
|
|
* @throws \PhpUnitsOfMeasure\Exception\NonStringUnitName
|
2018-04-03 11:35:25 +08:00
|
|
|
*/
|
2018-04-08 09:52:12 +08:00
|
|
|
public function __construct(float $value, string $unit)
|
2018-04-03 11:35:25 +08:00
|
|
|
{
|
2018-04-08 09:52:12 +08:00
|
|
|
$this->unit = setting('units.temperature');
|
|
|
|
$this->instance = new TemperatureUnit($value, $unit);
|
2018-04-03 11:35:25 +08:00
|
|
|
|
2018-04-08 09:52:12 +08:00
|
|
|
$this->units = [
|
|
|
|
'F' => round($this->instance->toUnit('F'), 2),
|
|
|
|
'f' => round($this->instance->toUnit('F'), 2),
|
|
|
|
'C' => round($this->instance->toUnit('C'), 2),
|
|
|
|
'c' => round($this->instance->toUnit('C'), 2),
|
2018-04-03 11:35:25 +08:00
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|