We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 21c3912 commit 9eb7335Copy full SHA for 9eb7335
Cmfcmf/OpenWeatherMap/Util/Unit.php
@@ -18,10 +18,12 @@
18
19
namespace Cmfcmf\OpenWeatherMap\Util;
20
21
+use JsonSerializable;
22
+
23
/**
24
* The unit class representing a unit object.
25
*/
-class Unit
26
+class Unit implements JsonSerializable
27
{
28
29
* @var float The value.
@@ -144,4 +146,19 @@ public function getFormatted()
144
146
return (string)$this->getValue();
145
147
}
148
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
164
0 commit comments