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;
|
namespace Symfony\Component\VarDumper\Caster;
|
||||||
|
|
||||||
use Ds\Deque;
|
use Ds\Collection;
|
||||||
use Ds\Map;
|
use Ds\Map;
|
||||||
use Ds\PriorityQueue;
|
use Ds\Pair;
|
||||||
use Ds\Queue;
|
|
||||||
use Ds\Set;
|
|
||||||
use Ds\Stack;
|
|
||||||
use Ds\Vector;
|
|
||||||
use Symfony\Component\VarDumper\Cloner\Stub;
|
use Symfony\Component\VarDumper\Cloner\Stub;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -27,23 +23,45 @@ use Symfony\Component\VarDumper\Cloner\Stub;
|
|||||||
*/
|
*/
|
||||||
class DsCaster
|
class DsCaster
|
||||||
{
|
{
|
||||||
/**
|
public static function castCollection(Collection $c, array $a, Stub $stub, bool $isNested): array
|
||||||
* @param Set|Deque|Vector|Stack|Queue|PriorityQueue $c
|
|
||||||
*/
|
|
||||||
public static function castDs($c, array $a, Stub $stub, bool $isNested): array
|
|
||||||
{
|
{
|
||||||
$prefix = Caster::PREFIX_VIRTUAL;
|
$a[Caster::PREFIX_VIRTUAL.'count'] = $c->count();
|
||||||
$a = $c->toArray();
|
$a[Caster::PREFIX_VIRTUAL.'capacity'] = $c->capacity();
|
||||||
$a[$prefix.'capacity'] = $c->capacity();
|
|
||||||
|
if (!$c instanceof Map) {
|
||||||
|
$a += $c->toArray();
|
||||||
|
}
|
||||||
|
|
||||||
return $a;
|
return $a;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function castMap(Map $c, array $a, Stub $stub, bool $isNested): array
|
public static function castMap(Map $c, array $a, Stub $stub, bool $isNested): array
|
||||||
{
|
{
|
||||||
$prefix = Caster::PREFIX_VIRTUAL;
|
foreach ($c as $k => $v) {
|
||||||
$a = $c->pairs()->toArray();
|
$a[] = new DsPairStub($k, $v);
|
||||||
$a[$prefix.'capacity'] = $c->capacity();
|
}
|
||||||
|
|
||||||
|
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;
|
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'],
|
'Memcached' => ['Symfony\Component\VarDumper\Caster\MemcachedCaster', 'castMemcached'],
|
||||||
|
|
||||||
'Ds\Set' => ['Symfony\Component\VarDumper\Caster\DsCaster', 'castDs'],
|
'Ds\Collection' => ['Symfony\Component\VarDumper\Caster\DsCaster', 'castCollection'],
|
||||||
'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\Map' => ['Symfony\Component\VarDumper\Caster\DsCaster', 'castMap'],
|
'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'],
|
':curl' => ['Symfony\Component\VarDumper\Caster\ResourceCaster', 'castCurl'],
|
||||||
':dba' => ['Symfony\Component\VarDumper\Caster\ResourceCaster', 'castDba'],
|
':dba' => ['Symfony\Component\VarDumper\Caster\ResourceCaster', 'castDba'],
|
||||||
|
Reference in New Issue
Block a user