Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ce8d371

Browse filesBrowse files
feature #13959 [VarDumper] Add catch-all-objects hook for casters (nicolas-grekas)
This PR was merged into the 2.7 branch. Discussion ---------- [VarDumper] Add catch-all-objects hook for casters | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - Allows to create generic casters for any type of objects Commits ------- 5999964 [VarDumper] Add catch-all-objects hook for casters
2 parents 2d2cd84 + 5999964 commit ce8d371
Copy full SHA for ce8d371

File tree

Expand file treeCollapse file tree

2 files changed

+51
-1
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+51
-1
lines changed

‎src/Symfony/Component/VarDumper/Cloner/AbstractCloner.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/VarDumper/Cloner/AbstractCloner.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ protected function castObject(Stub $stub, $isNested)
198198
$class,
199199
method_exists($class, '__debugInfo'),
200200
new \ReflectionClass($class),
201-
array_reverse(array($class => $class) + class_parents($class) + class_implements($class)),
201+
array_reverse(array('*' => '*', $class => $class) + class_parents($class) + class_implements($class)),
202202
);
203203

204204
$this->classInfo[$class] = $classInfo;

‎src/Symfony/Component/VarDumper/Tests/VarClonerTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/VarDumper/Tests/VarClonerTest.php
+50Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,56 @@ public function testClone()
131131
[useRefHandles:Symfony\Component\VarDumper\Cloner\Data:private] => -1
132132
)
133133
134+
EOTXT;
135+
$this->assertStringMatchesFormat($expected, print_r($clone, true));
136+
}
137+
138+
public function testCaster()
139+
{
140+
$cloner = new VarCloner(array(
141+
'*' => function ($obj, $array) {
142+
$array['foo'] = 123;
143+
144+
return $array;
145+
},
146+
__CLASS__ => function ($obj, $array) {
147+
return array();
148+
},
149+
));
150+
$clone = $cloner->cloneVar($this);
151+
152+
$expected = <<<EOTXT
153+
Symfony\Component\VarDumper\Cloner\Data Object
154+
(
155+
[data:Symfony\Component\VarDumper\Cloner\Data:private] => Array
156+
(
157+
[0] => Array
158+
(
159+
[0] => Symfony\Component\VarDumper\Cloner\Stub Object
160+
(
161+
[type] => object
162+
[class] => %s
163+
[value] =>
164+
[cut] => 0
165+
[handle] => %d
166+
[refCount] => 0
167+
[position] => 1
168+
)
169+
170+
)
171+
172+
[1] => Array
173+
(
174+
[foo] => 123
175+
)
176+
177+
)
178+
179+
[maxDepth:Symfony\Component\VarDumper\Cloner\Data:private] => 20
180+
[maxItemsPerDepth:Symfony\Component\VarDumper\Cloner\Data:private] => -1
181+
[useRefHandles:Symfony\Component\VarDumper\Cloner\Data:private] => -1
182+
)
183+
134184
EOTXT;
135185
$this->assertStringMatchesFormat($expected, print_r($clone, true));
136186
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.