Cleanup SI Unit classes and interface for REST responses; fixes to a few METAR parsing issues
This commit is contained in:
43
app/Providers/MeasurementsProvider.php
Executable file
43
app/Providers/MeasurementsProvider.php
Executable file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Exception;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use PhpUnitsOfMeasure\Exception\DuplicateUnitNameOrAlias;
|
||||
use PhpUnitsOfMeasure\Exception\NonStringUnitName;
|
||||
use PhpUnitsOfMeasure\Exception\UnknownUnitOfMeasure;
|
||||
use PhpUnitsOfMeasure\PhysicalQuantity\Length;
|
||||
use PhpUnitsOfMeasure\PhysicalQuantity\Temperature;
|
||||
use PhpUnitsOfMeasure\UnitOfMeasure;
|
||||
|
||||
/**
|
||||
* Add new measurement units to PhpUnitsOfMeasure
|
||||
*/
|
||||
class MeasurementsProvider extends ServiceProvider
|
||||
{
|
||||
public function boot(): void
|
||||
{
|
||||
try {
|
||||
$this->addTemperatures();
|
||||
} catch (Exception $e) {
|
||||
Log::error($e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add lowercase temperature units
|
||||
*
|
||||
* @throws NonStringUnitName
|
||||
* @throws UnknownUnitOfMeasure
|
||||
*/
|
||||
protected function addTemperatures()
|
||||
{
|
||||
$fUnit = Temperature::getUnit('F');
|
||||
$fUnit->addAlias('f');
|
||||
|
||||
$cUnit = Temperature::getUnit('C');
|
||||
$cUnit->addAlias('c');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user