Skip to content
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
30 changes: 30 additions & 0 deletions src/Symfony/Component/VarDumper/Caster/CutArrayStub.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?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;

/**
* Represents a cut array.
*
* @author Nicolas Grekas <p@tchwork.com>
*/
class CutArrayStub extends CutStub
{
public $preservedSubset;

public function __construct(array $value, array $preservedKeys)
{
parent::__construct($value);

$this->preservedSubset = array_intersect_key($value, array_flip($preservedKeys));
$this->cut -= count($this->preservedSubset);
}
}
13 changes: 1 addition & 12 deletions src/Symfony/Component/VarDumper/Caster/SplCaster.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,18 +160,7 @@ public static function castFileObject(\SplFileObject $c, array $a, Stub $stub, $
}

if (isset($a[$prefix.'fstat'])) {
$fstat = $a[$prefix.'fstat'];
$fstat = array(
'dev' => $fstat['dev'],
'ino' => $fstat['ino'],
'nlink' => $fstat['nlink'],
'rdev' => $fstat['rdev'],
'blksize' => $fstat['blksize'],
'blocks' => $fstat['blocks'],
'…' => '…'.(count($fstat) - 6),
);

$a[$prefix.'fstat'] = $fstat;
$a[$prefix.'fstat'] = new CutArrayStub($a[$prefix.'fstat'], array('dev', 'ino', 'nlink', 'rdev', 'blksize', 'blocks'));
}

return $a;
Expand Down
5 changes: 5 additions & 0 deletions src/Symfony/Component/VarDumper/Caster/StubCaster.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ public static function castStub(Stub $c, array $a, Stub $stub, $isNested)
}
}

public static function castCutArray(CutArrayStub $c, array $a, Stub $stub, $isNested)
{
return $isNested ? $c->preservedSubset : $a;
}

public static function cutInternals($obj, array $a, Stub $stub, $isNested)
{
if ($isNested) {
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Component/VarDumper/Cloner/AbstractCloner.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ abstract class AbstractCloner implements ClonerInterface
{
public static $defaultCasters = array(
'Symfony\Component\VarDumper\Caster\CutStub' => 'Symfony\Component\VarDumper\Caster\StubCaster::castStub',
'Symfony\Component\VarDumper\Caster\CutArrayStub' => 'Symfony\Component\VarDumper\Caster\StubCaster::castCutArray',
'Symfony\Component\VarDumper\Caster\ConstStub' => 'Symfony\Component\VarDumper\Caster\StubCaster::castStub',

'Closure' => 'Symfony\Component\VarDumper\Caster\ReflectionCaster::castClosure',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,14 @@ public function testCastFileObject()
]
flags: DROP_NEW_LINE|SKIP_EMPTY
maxLineLen: 0
fstat: array:7 [
fstat: array:26 [
"dev" => %d
"ino" => %d
"nlink" => %d
"rdev" => 0
"blksize" => %d
"blocks" => %d
"…" => "…20"
…20
]
eof: false
key: 0
Expand Down