Move internal unit definitions to config file #189
This commit is contained in:
@@ -85,7 +85,7 @@ class Flight extends BaseModel
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
$distance = (float) $this->attributes['distance'];
|
$distance = (float) $this->attributes['distance'];
|
||||||
return new Distance($distance, Distance::STORAGE_UNIT);
|
return new Distance($distance, config('phpvms.internal_units.distance'));
|
||||||
} catch (NonNumericValue $e) {
|
} catch (NonNumericValue $e) {
|
||||||
return 0;
|
return 0;
|
||||||
} catch (NonStringUnitName $e) {
|
} catch (NonStringUnitName $e) {
|
||||||
@@ -100,7 +100,9 @@ class Flight extends BaseModel
|
|||||||
public function setDistanceAttribute($value)
|
public function setDistanceAttribute($value)
|
||||||
{
|
{
|
||||||
if($value instanceof Distance) {
|
if($value instanceof Distance) {
|
||||||
$this->attributes['distance'] = $value->toUnit(Distance::STORAGE_UNIT);
|
$this->attributes['distance'] = $value->toUnit(
|
||||||
|
config('phpvms.internal_units.distance')
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
$this->attributes['distance'] = $value;
|
$this->attributes['distance'] = $value;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ class Pirep extends BaseModel
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
$distance = (float) $this->attributes['distance'];
|
$distance = (float) $this->attributes['distance'];
|
||||||
return new Distance($distance, Distance::STORAGE_UNIT);
|
return new Distance($distance, config('phpvms.internal_units.distance'));
|
||||||
} catch (NonNumericValue $e) {
|
} catch (NonNumericValue $e) {
|
||||||
return 0;
|
return 0;
|
||||||
} catch (NonStringUnitName $e) {
|
} catch (NonStringUnitName $e) {
|
||||||
@@ -130,7 +130,8 @@ class Pirep extends BaseModel
|
|||||||
public function setDistanceAttribute($value): void
|
public function setDistanceAttribute($value): void
|
||||||
{
|
{
|
||||||
if ($value instanceof Distance) {
|
if ($value instanceof Distance) {
|
||||||
$this->attributes['distance'] = $value->toUnit(Distance::STORAGE_UNIT);
|
$this->attributes['distance'] = $value->toUnit(
|
||||||
|
config('phpvms.internal_units.distance'));
|
||||||
} else {
|
} else {
|
||||||
$this->attributes['distance'] = $value;
|
$this->attributes['distance'] = $value;
|
||||||
}
|
}
|
||||||
@@ -148,7 +149,7 @@ class Pirep extends BaseModel
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
$distance = (float) $this->attributes['planned_distance'];
|
$distance = (float) $this->attributes['planned_distance'];
|
||||||
return new Distance($distance, Distance::STORAGE_UNIT);
|
return new Distance($distance, config('phpvms.internal_units.distance'));
|
||||||
} catch (NonNumericValue $e) {
|
} catch (NonNumericValue $e) {
|
||||||
return 0;
|
return 0;
|
||||||
} catch (NonStringUnitName $e) {
|
} catch (NonStringUnitName $e) {
|
||||||
@@ -163,7 +164,9 @@ class Pirep extends BaseModel
|
|||||||
public function setPlannedDistanceAttribute($value)
|
public function setPlannedDistanceAttribute($value)
|
||||||
{
|
{
|
||||||
if ($value instanceof Distance) {
|
if ($value instanceof Distance) {
|
||||||
$this->attributes['planned_distance'] = $value->toUnit(Distance::STORAGE_UNIT);
|
$this->attributes['planned_distance'] = $value->toUnit(
|
||||||
|
config('phpvms.internal_units.distance')
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
$this->attributes['planned_distance'] = $value;
|
$this->attributes['planned_distance'] = $value;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,11 +9,6 @@ use Illuminate\Contracts\Support\Arrayable;
|
|||||||
*/
|
*/
|
||||||
class Altitude extends \PhpUnitsOfMeasure\PhysicalQuantity\Length implements Arrayable
|
class Altitude extends \PhpUnitsOfMeasure\PhysicalQuantity\Length implements Arrayable
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* The unit that this is stored as
|
|
||||||
*/
|
|
||||||
public const STORAGE_UNIT = 'feet';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
@@ -40,6 +35,8 @@ class Altitude extends \PhpUnitsOfMeasure\PhysicalQuantity\Length implements Arr
|
|||||||
*/
|
*/
|
||||||
public function toArray()
|
public function toArray()
|
||||||
{
|
{
|
||||||
return round($this->toUnit(self::STORAGE_UNIT), 2);
|
return round($this->toUnit(
|
||||||
|
config('phpvms.internal_units.altitude')
|
||||||
|
), 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,11 +9,6 @@ use Illuminate\Contracts\Support\Arrayable;
|
|||||||
*/
|
*/
|
||||||
class Distance extends \PhpUnitsOfMeasure\PhysicalQuantity\Length implements Arrayable
|
class Distance extends \PhpUnitsOfMeasure\PhysicalQuantity\Length implements Arrayable
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* The unit that this is stored as
|
|
||||||
*/
|
|
||||||
public const STORAGE_UNIT = 'nmi';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
@@ -41,6 +36,8 @@ class Distance extends \PhpUnitsOfMeasure\PhysicalQuantity\Length implements Arr
|
|||||||
*/
|
*/
|
||||||
public function toArray()
|
public function toArray()
|
||||||
{
|
{
|
||||||
return round($this->toUnit(self::STORAGE_UNIT), 2);
|
return round($this->toUnit(
|
||||||
|
config('phpvms.internal_units.distance')
|
||||||
|
), 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,6 +41,8 @@ class Mass extends \PhpUnitsOfMeasure\PhysicalQuantity\Mass implements Arrayable
|
|||||||
*/
|
*/
|
||||||
public function toArray()
|
public function toArray()
|
||||||
{
|
{
|
||||||
return round($this->toUnit(self::STORAGE_UNIT), 2);
|
return round($this->toUnit(
|
||||||
|
config('phpvms.internal_units.mass')
|
||||||
|
), 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,11 +9,6 @@ use Illuminate\Contracts\Support\Arrayable;
|
|||||||
*/
|
*/
|
||||||
class Velocity extends \PhpUnitsOfMeasure\PhysicalQuantity\Velocity implements Arrayable
|
class Velocity extends \PhpUnitsOfMeasure\PhysicalQuantity\Velocity implements Arrayable
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* The unit that this is stored as
|
|
||||||
*/
|
|
||||||
public const STORAGE_UNIT = 'knot';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
@@ -30,7 +25,7 @@ class Velocity extends \PhpUnitsOfMeasure\PhysicalQuantity\Velocity implements A
|
|||||||
public function toObject()
|
public function toObject()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'knot' => round($this->toUnit('knot'), 2),
|
'knots' => round($this->toUnit('knots'), 2),
|
||||||
'km/h' => round($this->toUnit('km/h'), 2),
|
'km/h' => round($this->toUnit('km/h'), 2),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@@ -40,6 +35,8 @@ class Velocity extends \PhpUnitsOfMeasure\PhysicalQuantity\Velocity implements A
|
|||||||
*/
|
*/
|
||||||
public function toArray()
|
public function toArray()
|
||||||
{
|
{
|
||||||
return round($this->toUnit(self::STORAGE_UNIT), 2);
|
return round($this->toUnit(
|
||||||
|
config('phpvms.internal_units.velocity')
|
||||||
|
), 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,11 +9,6 @@ use Illuminate\Contracts\Support\Arrayable;
|
|||||||
*/
|
*/
|
||||||
class Volume extends \PhpUnitsOfMeasure\PhysicalQuantity\Volume implements Arrayable
|
class Volume extends \PhpUnitsOfMeasure\PhysicalQuantity\Volume implements Arrayable
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* The unit that this is stored as
|
|
||||||
*/
|
|
||||||
public const STORAGE_UNIT = 'gal';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
@@ -40,6 +35,8 @@ class Volume extends \PhpUnitsOfMeasure\PhysicalQuantity\Volume implements Array
|
|||||||
*/
|
*/
|
||||||
public function toArray()
|
public function toArray()
|
||||||
{
|
{
|
||||||
return round($this->toUnit(self::STORAGE_UNIT), 2);
|
return round($this->toUnit(
|
||||||
|
config('phpvms.internal_units.volume')
|
||||||
|
), 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,4 +46,17 @@ return [
|
|||||||
* URL to the latest version file
|
* URL to the latest version file
|
||||||
*/
|
*/
|
||||||
'version_file' => 'http://downloads.phpvms.net/VERSION',
|
'version_file' => 'http://downloads.phpvms.net/VERSION',
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DO NOT CHANGE THESE! It will result in messed up data
|
||||||
|
* The setting you're looking for is in the admin panel,
|
||||||
|
* under settings, for the display units
|
||||||
|
*/
|
||||||
|
'internal_units' => [
|
||||||
|
'altitude' => 'feet',
|
||||||
|
'distance' => 'nmi',
|
||||||
|
'mass' => 'lbs',
|
||||||
|
'velocity' => 'knots',
|
||||||
|
'volume' => 'gallons',
|
||||||
|
],
|
||||||
];
|
];
|
||||||
|
|||||||
Reference in New Issue
Block a user