Skip to content
This repository was archived by the owner on Jan 23, 2019. It is now read-only.

Commit fabb9c6

Browse files
committed
up
1 parent 5a01aa7 commit fabb9c6

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

src/Helpers/DataHelper.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,12 @@ public static function decode($txt, $allowedClasses = false)
4545
public static function toArray($data, $recursive = false)
4646
{
4747
// Ensure the input data is an array.
48-
if (is_object($data) && $data instanceof \Traversable) {
49-
$data = iterator_to_array($data);
50-
// } elseif (is_object($data)) {
51-
// $data = get_object_vars($data);
48+
if (is_object($data)) {
49+
if ($data instanceof \Traversable) {
50+
$data = iterator_to_array($data);
51+
} elseif (method_exists($data, 'toArray')) {
52+
$data = $data->toArray();
53+
}
5254
} else {
5355
$data = (array)$data;
5456
}

src/Helpers/Obj.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,13 @@ public static function make($class)
3636

3737
return self::$objects[$class];
3838
}
39+
40+
/**
41+
* @param $object
42+
* @return bool
43+
*/
44+
public static function isArrayable($object)
45+
{
46+
return $object instanceof \ArrayAccess || method_exists($object, 'toArray');
47+
}
3948
}

0 commit comments

Comments
 (0)