forked from yiisoft/yii2-mongodb
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathMongoHelper.php
More file actions
39 lines (34 loc) · 854 Bytes
/
MongoHelper.php
File metadata and controls
39 lines (34 loc) · 854 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
namespace yii\mongodb;
class MongoHelper
{
/**
* Converts all instances of stdClass to array recursively
* @param \stdClass $row
* @return array
*/
public static function resultToArray($row)
{
//TODO: Change this by using \MongoDB\Driver\Cursor::setTypeMap
if ($row instanceof \stdClass) {
$row = (array)$row;
}
if (is_array($row)) {
foreach($row as $key => $value) {
$row[$key] = self::resultToArray($value);
}
}
return $row;
}
/**
* @param \MongoDB\Driver\Cursor $cursor
* @return array first value of cursor.
*/
public static function cursorFirst($cursor)
{
foreach($cursor as $row) {
return self::resultToArray($row);
}
return null;
}
}