implements ArrayAccess for casting to type #189

This commit is contained in:
Nabeel Shahzad
2018-02-10 22:04:30 -06:00
parent cb02a7c15e
commit f14a9e3ba1
9 changed files with 126 additions and 17 deletions

View File

@@ -1,12 +1,13 @@
<?php
namespace App\Support\Units;
use Illuminate\Contracts\Support\Arrayable;
/**
* Wrap the converter class
* @package App\Support\Units
*/
class Volume extends \PhpUnitsOfMeasure\PhysicalQuantity\Volume
class Volume extends \PhpUnitsOfMeasure\PhysicalQuantity\Volume implements Arrayable
{
/**
* The unit that this is stored as
@@ -26,11 +27,19 @@ class Volume extends \PhpUnitsOfMeasure\PhysicalQuantity\Volume
/**
* For the HTTP Resource call
*/
public function toJson()
public function toObject()
{
return [
'gal' => round($this->toUnit('gal'), 2),
'liters' => round($this->toUnit('liters'), 2),
];
}
/**
* Get the instance as an array.
*/
public function toArray()
{
return round($this->toUnit(self::STORAGE_UNIT), 2);
}
}