Skip to content

Commit

Permalink
[VarDumper] Add catch-all-objects hook for casters
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas committed Mar 18, 2015
1 parent 59ca5b3 commit 5999964
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Symfony/Component/VarDumper/Cloner/AbstractCloner.php
Expand Up @@ -192,7 +192,7 @@ protected function castObject(Stub $stub, $isNested)
$class,
method_exists($class, '__debugInfo'),
new \ReflectionClass($class),
array_reverse(array($class => $class) + class_parents($class) + class_implements($class)),
array_reverse(array('*' => '*', $class => $class) + class_parents($class) + class_implements($class)),
);

$this->classInfo[$class] = $classInfo;
Expand Down
50 changes: 50 additions & 0 deletions src/Symfony/Component/VarDumper/Tests/VarClonerTest.php
Expand Up @@ -131,6 +131,56 @@ public function testClone()
[useRefHandles:Symfony\Component\VarDumper\Cloner\Data:private] => -1
)
EOTXT;
$this->assertStringMatchesFormat($expected, print_r($clone, true));
}

public function testCaster()
{
$cloner = new VarCloner(array(
'*' => function ($obj, $array) {
$array['foo'] = 123;

return $array;
},
__CLASS__ => function ($obj, $array) {
return array();
},
));
$clone = $cloner->cloneVar($this);

$expected = <<<EOTXT
Symfony\Component\VarDumper\Cloner\Data Object
(
[data:Symfony\Component\VarDumper\Cloner\Data:private] => Array
(
[0] => Array
(
[0] => Symfony\Component\VarDumper\Cloner\Stub Object
(
[type] => object
[class] => %s
[value] =>
[cut] => 0
[handle] => %d
[refCount] => 0
[position] => 1
)
)
[1] => Array
(
[foo] => 123
)
)
[maxDepth:Symfony\Component\VarDumper\Cloner\Data:private] => 20
[maxItemsPerDepth:Symfony\Component\VarDumper\Cloner\Data:private] => -1
[useRefHandles:Symfony\Component\VarDumper\Cloner\Data:private] => -1
)
EOTXT;
$this->assertStringMatchesFormat($expected, print_r($clone, true));
}
Expand Down

0 comments on commit 5999964

Please sign in to comment.