Skip to content

Commit 3524350

Browse files
committed
Update Converter.php
1 parent 4ea1fd2 commit 3524350

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

src/Filesystem/Converter.php

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,25 @@ final class Converter
2323
*
2424
* @access public
2525
* @param array $array
26-
* @return object
26+
* @param bool $stric, Convert all sub-items
27+
* @return mixed
2728
*/
28-
public static function toObject($array)
29+
public static function toObject($array, $stric = false)
2930
{
30-
return (object)Json::decode(
31-
Json::encode($array),
32-
false
33-
);
31+
if ( !TypeCheck::isArray($array) ) {
32+
return $array;
33+
}
34+
if ( $stric ) {
35+
return (object)Json::decode(
36+
Json::encode($array),
37+
false
38+
);
39+
}
40+
$obj = new \stdClass;
41+
foreach ( $array as $item => $val ) {
42+
$obj->{$item} = $val;
43+
}
44+
return (object)$obj;
3445
}
3546

3647
/**

0 commit comments

Comments
 (0)