8000 feature #14034 [VarDumper] add caster for MongoCursor objects (nicola… · symfony/symfony@a464f37 · GitHub
[go: up one dir, main page]

Skip to content

Commit a464f37

Browse files
committed
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
2 parents d3b8b84 + 1008e6c commit a464f37

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed
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+
}

src/Symfony/Component/VarDumper/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)
0