8000 [VarDumper] fix dumping Ds maps and pairs by nicolas-grekas · Pull Request #30349 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[VarDumper] fix dumping Ds maps and pairs #30349

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[VarDumper] fix dumping Ds maps and pairs
  • Loading branch information
nicolas-grekas committed Feb 22, 2019
commit 45869ac10c659daaa9a1f43e003f78cd8ed49cc5
50 changes: 34 additions & 16 deletions src/Symfony/Component/VarDumper/Caster/DsCaster.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -27,23 +23,45 @@
*/
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;
}
Expand Down
8000
28 changes: 28 additions & 0 deletions src/Symfony/Component/VarDumper/Caster/DsPairStub.php
Original file line number Diff line number Diff line change
@@ -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,
];
}
}
9 changes: 3 additions & 6 deletions src/Symfony/Component/VarDumper/Cloner/AbstractCloner.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down
0