feature #14034 [VarDumper] add caster for MongoCursor objects (nicolas-grekas)

This PR was merged into the 2.7 branch.

Discussion
----------

[VarDumper] add caster for MongoCursor objects

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

This one is inspired from [PsySH's equivalent](https://github.com/bobthecow/psysh/blob/master/src/Psy/Presenter/MongoCursorPresenter.php).
Looking at the interface of the Mongo extension, the other classes may need a caster too.
So if a real Mongo user can write casters for them, that'd be great! (in an other PR, on top of this one)

Commits
-------

1008e6c [VarDumper] add caster for MongoCursor objects
This commit is contained in:
Fabien Potencier 2015-03-24 12:09:28 +01:00
commit a464f37734
2 changed files with 38 additions and 0 deletions

View File

@ -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;
}
}

View File

@ -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',