Skip to content

Commit 9eb7335

Browse files
committed
added interface JsonSerializable to Util\Unit class
1 parent 21c3912 commit 9eb7335

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

Cmfcmf/OpenWeatherMap/Util/Unit.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@
1818

1919
namespace Cmfcmf\OpenWeatherMap\Util;
2020

21+
use JsonSerializable;
22+
2123
/**
2224
* The unit class representing a unit object.
2325
*/
24-
class Unit
26+
class Unit implements JsonSerializable
2527
{
2628
/**
2729
* @var float The value.
@@ -144,4 +146,19 @@ public function getFormatted()
144146
return (string)$this->getValue();
145147
}
146148
}
149+
150+
/**
151+
* Get Unit properties when encoding to JSON
152+
* @return array
153+
*/
154+
public function jsonSerialize ()
155+
{
156+
return [
157+
'value' => $this->getValue(),
158+
'unit' => $this->getUnit(),
159+
'description' => $this->getDescription(),
160+
'precision' => $this->getPrecision(),
161+
];
162+
}
163+
147164
}

0 commit comments

Comments
 (0)