Skip to content

Commit

Permalink
[VarDumper] add caster for MongoCursor objects
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas committed Mar 24, 2015
1 parent 1a4d7d7 commit 1008e6c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/Symfony/Component/VarDumper/Caster/MongoCaster.php
@@ -0,0 +1,36 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\VarDumper\Caster;

use Symfony\Component\VarDumper\Cloner\Stub;

/**
* Casts classes from the MongoDb extension to array representation.
*
* @author Nicolas Grekas <p@tchwork.com>
*/
class MongoCaster
{
public static function castCursor(\MongoCursorInterface $cursor, array $a, Stub $stub, $isNested)
{
$prefix = "\0~\0";

if ($info = $cursor->info()) {
foreach ($info as $k => $v) {
$a[$prefix.$k] = $v;
}
}
$a[$prefix.'dead'] = $cursor->dead();

return $a;
}
}
2 changes: 2 additions & 0 deletions src/Symfony/Component/VarDumper/Cloner/AbstractCloner.php
Expand Up @@ -76,6 +76,8 @@ abstract class AbstractCloner implements ClonerInterface
'SplObjectStorage' => 'Symfony\Component\VarDumper\Caster\SplCaster::castObjectStorage',
'SplPriorityQueue' => 'Symfony\Component\VarDumper\Caster\SplCaster::castHeap',

'MongoCursorInterface' => 'Symfony\Component\VarDumper\Caster\MongoCaster::castCursor',

':curl' => 'Symfony\Component\VarDumper\Caster\ResourceCaster::castCurl',
':dba' => 'Symfony\Component\VarDumper\Caster\ResourceCaster::castDba',
':dba persistent' => 'Symfony\Component\VarDumper\Caster\ResourceCaster::castDba',
Expand Down

0 comments on commit 1008e6c

Please sign in to comment.