Skip to content

Commit 34eb557

Browse files
[VarDumper] add caster for MongoCursor objects
1 parent e964f4c commit 34eb557

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

Caster/MongoCaster.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\VarDumper\Caster;
13+
14+
use Symfony\Component\VarDumper\Cloner\Stub;
15+
16+
/**
17+
* Casts classes from the MongoDb extension to array representation.
18+
*
19+
* @author Nicolas Grekas <p@tchwork.com>
20+
*/
21+
class MongoCaster
22+
{
23+
public static function castCursor(\MongoCursorInterface $cursor, array $a, Stub $stub, $isNested)
24+
{
25+
$prefix = "\0~\0";
26+
27+
if ($info = $cursor->info()) {
28+
foreach ($info as $k => $v) {
29+
$a[$prefix.$k] = $v;
30+
}
31+
}
32+
$a[$prefix.'dead'] = $cursor->dead();
33+
34+
return $a;
35+
}
36+
}

Cloner/AbstractCloner.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ abstract class AbstractCloner implements ClonerInterface
7676
'SplObjectStorage' => 'Symfony\Component\VarDumper\Caster\SplCaster::castObjectStorage',
7777
'SplPriorityQueue' => 'Symfony\Component\VarDumper\Caster\SplCaster::castHeap',
7878

79+
'MongoCursorInterface' => 'Symfony\Component\VarDumper\Caster\MongoCaster::castCursor',
80+
7981
':curl' => 'Symfony\Component\VarDumper\Caster\ResourceCaster::castCurl',
8082
':dba' => 'Symfony\Component\VarDumper\Caster\ResourceCaster::castDba',
8183
':dba persistent' => 'Symfony\Component\VarDumper\Caster\ResourceCaster::castDba',

0 commit comments

Comments
 (0)