bug #30349 [VarDumper] fix dumping Ds maps and pairs (nicolas-grekas)
This PR was merged into the 4.3-dev branch.
Discussion
----------
[VarDumper] fix dumping Ds maps and pairs
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | -
| License | MIT
| Doc PR | -
Fixes https://github.com/symfony/symfony/pull/30311#issuecomment-466457434
![image](https://user-images.githubusercontent.com/243674/53267273-41260e80-36e3-11e9-8723-a73bf0690a01.png)
Commits
-------
45869ac10c
[VarDumper] fix dumping Ds maps and pairs
This commit is contained in:
commit
2e8bf334ca
@ -11,13 +11,9 @@
|
||||
|
||||
namespace Symfony\Component\VarDumper\Caster;
|
||||
|
||||
use Ds\Deque;
|
||||
use Ds\Collection;
|
||||
use Ds\Map;
|
||||
use Ds\PriorityQueue;
|
||||
use Ds\Queue;
|
||||
use Ds\Set;
|
||||
use Ds\Stack;
|
||||
use Ds\Vector;
|
||||
use Ds\Pair;
|
||||
use Symfony\Component\VarDumper\Cloner\Stub;
|
||||
|
||||
/**
|
||||
@ -27,23 +23,45 @@ use Symfony\Component\VarDumper\Cloner\Stub;
|
||||
*/
|
||||
class DsCaster
|
||||
{
|
||||
/**
|
||||
* @param Set|Deque|Vector|Stack|Queue|PriorityQueue $c
|
||||
*/
|
||||
public static function castDs($c, array $a, Stub $stub, bool $isNested): array
|
||||
public static function castCollection(Collection $c, array $a, Stub $stub, bool $isNested): array
|
||||
{
|
||||
$prefix = Caster::PREFIX_VIRTUAL;
|
||||
$a = $c->toArray();
|
||||
$a[$prefix.'capacity'] = $c->capacity();
|
||||
$a[Caster::PREFIX_VIRTUAL.'count'] = $c->count();
|
||||
$a[Caster::PREFIX_VIRTUAL.'capacity'] = $c->capacity();
|
||||
|
||||
if (!$c instanceof Map) {
|
||||
$a += $c->toArray();
|
||||
}
|
||||
|
||||
return $a;
|
||||
}
|
||||
|
||||
public static function castMap(Map $c, array $a, Stub $stub, bool $isNested): array
|
||||
{
|
||||
$prefix = Caster::PREFIX_VIRTUAL;
|
||||
$a = $c->pairs()->toArray();
|
||||
$a[$prefix.'capacity'] = $c->capacity();
|
||||
foreach ($c as $k => $v) {
|
||||
$a[] = new DsPairStub($k, $v);
|
||||
}
|
||||
|
||||
return $a;
|
||||
}
|
||||
|
||||
public static function castPair(Pair $c, array $a, Stub $stub, bool $isNested): array
|
||||
{
|
||||
foreach ($c->toArray() as $k => $v) {
|
||||
$a[Caster::PREFIX_VIRTUAL.$k] = $v;
|
||||
}
|
||||
|
||||
return $a;
|
||||
}
|
||||
|
||||
public static function castPairStub(DsPairStub $c, array $a, Stub $stub, bool $isNested): array
|
||||
{
|
||||
if ($isNested) {
|
||||
$stub->class = Pair::class;
|
||||
$stub->value = null;
|
||||
$stub->handle = 0;
|
||||
|
||||
$a = $c->value;
|
||||
}
|
||||
|
||||
return $a;
|
||||
}
|
||||
|
28
src/Symfony/Component/VarDumper/Caster/DsPairStub.php
Normal file
28
src/Symfony/Component/VarDumper/Caster/DsPairStub.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?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;
|
||||
|
||||
/**
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
*/
|
||||
class DsPairStub extends Stub
|
||||
{
|
||||
public function __construct($key, $value)
|
||||
{
|
||||
$this->value = [
|
||||
Caster::PREFIX_VIRTUAL.'key' => $key,
|
||||
Caster::PREFIX_VIRTUAL.'value' => $value,
|
||||
];
|
||||
}
|
||||
}
|
@ -125,13 +125,10 @@ abstract class AbstractCloner implements ClonerInterface
|
||||
|
||||
'Memcached' => ['Symfony\Component\VarDumper\Caster\MemcachedCaster', 'castMemcached'],
|
||||
|
||||
'Ds\Set' => ['Symfony\Component\VarDumper\Caster\DsCaster', 'castDs'],
|
||||
'Ds\Vector' => ['Symfony\Component\VarDumper\Caster\DsCaster', 'castDs'],
|
||||
'Ds\Deque' => ['Symfony\Component\VarDumper\Caster\DsCaster', 'castDs'],
|
||||
'Ds\Stack' => ['Symfony\Component\VarDumper\Caster\DsCaster', 'castDs'],
|
||||
'Ds\Queue' => ['Symfony\Component\VarDumper\Caster\DsCaster', 'castDs'],
|
||||
'Ds\PriorityQueue' => ['Symfony\Component\VarDumper\Caster\DsCaster', 'castDs'],
|
||||
'Ds\Collection' => ['Symfony\Component\VarDumper\Caster\DsCaster', 'castCollection'],
|
||||
'Ds\Map' => ['Symfony\Component\VarDumper\Caster\DsCaster', 'castMap'],
|
||||
'Ds\Pair' => ['Symfony\Component\VarDumper\Caster\DsCaster', 'castPair'],
|
||||
'Symfony\Component\VarDumper\Caster\DsPairStub' => ['Symfony\Component\VarDumper\Caster\DsCaster', 'castPairStub'],
|
||||
|
||||
':curl' => ['Symfony\Component\VarDumper\Caster\ResourceCaster', 'castCurl'],
|
||||
':dba' => ['Symfony\Component\VarDumper\Caster\ResourceCaster', 'castDba'],
|
||||
|
Reference in New Issue
Block a user