implements ArrayAccess for casting to type #189
This commit is contained in:
@@ -1,13 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Support\Units;
|
||||
use Illuminate\Contracts\Support\Arrayable;
|
||||
|
||||
/**
|
||||
* Class Mass
|
||||
* @package App\Support\Units
|
||||
*/
|
||||
class Mass extends \PhpUnitsOfMeasure\PhysicalQuantity\Mass
|
||||
class Mass extends \PhpUnitsOfMeasure\PhysicalQuantity\Mass implements Arrayable
|
||||
{
|
||||
/**
|
||||
* The unit this is stored as
|
||||
*/
|
||||
public const STORAGE_UNIT = 'lbs';
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
@@ -15,17 +21,26 @@ class Mass extends \PhpUnitsOfMeasure\PhysicalQuantity\Mass
|
||||
{
|
||||
$unit = setting('general.weight_unit');
|
||||
$value = $this->toUnit($unit);
|
||||
return (string)round($value, 2);
|
||||
return (string) round($value, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* For the HTTP Resource call
|
||||
*/
|
||||
public function toJson()
|
||||
public function toObject()
|
||||
{
|
||||
return [
|
||||
'kg' => round($this->toUnit('kg'), 2),
|
||||
'lgs' => round($this->toUnit('lbs'), 2),
|
||||
'lbs' => round($this->toUnit('lbs'), 2),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the instance as an array.
|
||||
* @return array
|
||||
*/
|
||||
public function toArray()
|
||||
{
|
||||
return round($this->toUnit(self::STORAGE_UNIT), 2);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user