Skip to content

Commit ebd0ffc

Browse files
committed
feat: add now(), toArray()
1 parent 38eadaa commit ebd0ffc

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

src/UnderscoreBase.php

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,22 @@ public function asArray($data)
6969
return (array) $data;
7070
}
7171

72+
/**
73+
* Convert the data items to array.
74+
*
75+
* @return array
76+
*/
77+
public function toArray()
78+
{
79+
return array_map(function ($value) {
80+
if (\is_scalar($value)) {
81+
return $value;
82+
}
83+
84+
return $this->asArray($value);
85+
}, $this->data);
86+
}
87+
7288
/**
7389
* Flatten a multi dimension array to 1 dimension.
7490
*
@@ -192,10 +208,27 @@ public function jsonSerialize()
192208
*/
193209
public function __toString()
194210
{
195-
return \json_encode($this->data);
211+
return \json_encode($this->toArray());
196212
}
197213

198-
public static function _($data)
214+
/**
215+
* The current time in millisec.
216+
*
217+
* @return float
218+
*/
219+
public function now()
220+
{
221+
return microtime(1) * 1000;
222+
}
223+
224+
/**
225+
* A static shortcut to constructor.
226+
*
227+
* @param mixed $data
228+
*
229+
* @return self
230+
*/
231+
public static function _($data = null)
199232
{
200233
return new static($data);
201234
}

0 commit comments

Comments
 (0)