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 ec124e0

Browse filesBrowse files
[VarDumper] Fix generic casters calling order
1 parent dc296cc commit ec124e0
Copy full SHA for ec124e0

File tree

Expand file treeCollapse file tree

4 files changed

+31
-26
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+31
-26
lines changed

‎src/Symfony/Component/VarDumper/Caster/DoctrineCaster.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/VarDumper/Caster/DoctrineCaster.php
+17-16Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,34 +25,35 @@ class DoctrineCaster
2525
{
2626
public static function castCommonProxy(CommonProxy $proxy, array $a, Stub $stub, $isNested)
2727
{
28-
unset(
29-
$a['__cloner__'],
30-
$a['__initializer__']
31-
);
32-
$stub->cut += 2;
28+
foreach (array('__cloner__', '__initializer__') as $k) {
29+
if (array_key_exists($k, $a)) {
30+
unset($a[$k]);
31+
++$stub->cut;
32+
}
33+
}
3334

3435
return $a;
3536
}
3637

3738
public static function castOrmProxy(OrmProxy $proxy, array $a, Stub $stub, $isNested)
3839
{
39-
$prefix = "\0Doctrine\\ORM\\Proxy\\Proxy\0";
40-
unset(
41-
$a[$prefix.'_entityPersister'],
42-
$a[$prefix.'_identifier']
43-
);
44-
$stub->cut += 2;
40+
foreach (array('_entityPersister', '_identifier') as $k) {
41+
if (array_key_exists($k = "\0Doctrine\\ORM\\Proxy\\Proxy\0".$k, $a)) {
42+
unset($a[$k]);
43+
++$stub->cut;
44+
}
45+
}
4546

4647
return $a;
4748
}
4849

4950
public static function castPersistentCollection(PersistentCollection $coll, array $a, Stub $stub, $isNested)
5051
{
51-
$prefix = "\0Doctrine\\ORM\\PersistentCollection\0";
52-
53-
$a[$prefix.'snapshot'] = new CutStub($a[$prefix.'snapshot']);
54-
$a[$prefix.'association'] = new CutStub($a[$prefix.'association']);
55-
$a[$prefix.'typeClass'] = new CutStub($a[$prefix.'typeClass']);
52+
foreach (array('snapshot', 'association', 'typeClass') as $k) {
53+
if (array_key_exists($k = "\0Doctrine\\ORM\\PersistentCollection\0".$k, $a)) {
54+
$a[$k] = new CutStub($a[$k]);
55+
}
56+
}
5657

5758
return $a;
5859
}

‎src/Symfony/Component/VarDumper/Caster/ExceptionCaster.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/VarDumper/Caster/ExceptionCaster.php
+8-4Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,12 @@ class ExceptionCaster
4343
public static function castException(\Exception $e, array $a, Stub $stub, $isNested, $filter = 0)
4444
{
4545
$xPrefix = PHP_VERSION_ID >= 70000 ? "\0BaseException\0" : "\0Exception\0";
46-
$trace = $a[$xPrefix.'trace'];
47-
unset($a[$xPrefix.'trace']); // Ensures the trace is always last
46+
if (isset($a[$xPrefix.'trace'])) {
47+
$trace = $a[$xPrefix.'trace'];
48+
unset($a[$xPrefix.'trace']); // Ensures the trace is always last
49+
} else {
50+
$trace = array();
51+
}
4852

4953
if (!($filter & Caster::EXCLUDE_VERBOSE)) {
5054
static::filterTrace($trace, static::$traceArgs);
@@ -74,9 +78,9 @@ public static function castThrowingCasterException(ThrowingCasterException $e, a
7478
{
7579
$prefix = Caster::PREFIX_PROTECTED;
7680
$xPrefix = PHP_VERSION_ID >= 70000 ? "\0BaseException\0" : "\0Exception\0";
77-
$b = (array) $a[$xPrefix.'previous'];
7881

79-
if (isset($a[$xPrefix.'trace'][0])) {
82+
if (isset($a[$xPrefix.'previous'], $a[$xPrefix.'trace'][0])) {
83+
$b = (array) $a[$xPrefix.'previous'];
8084
$b[$xPrefix.'trace'][0] += array(
8185
'file' => $b[$prefix.'file'],
8286
'line' => $b[$prefix.'line'],

‎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
@@ -214,7 +214,7 @@ protected function castObject(Stub $stub, $isNested)
214214
$classInfo = array(
215215
$class,
216216
new \ReflectionClass($class),
217-
array_reverse(array('*' => '*', $class => $class) + class_parents($class) + class_implements($class)),
217+
array_reverse(array($class => $class) + class_parents($class) + class_implements($class) + array('*' => '*')),
218218
);
219219

220220
$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
+5-5Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,12 @@ public function testCaster()
139139
{
140140
$cloner = new VarCloner(array(
141141
'*' => function ($obj, $array) {
142-
$array['foo'] = 123;
143-
144-
return $array;
142+
return array('foo' => 123);
145143
},
146144
__CLASS__ => function ($obj, $array) {
147-
return array();
145+
++$array['foo'];
146+
147+
return $array;
148148
},
149149
));
150150
$clone = $cloner->cloneVar($this);
@@ -171,7 +171,7 @@ public function testCaster()
171171
172172
[1] => Array
173173
(
174-
[foo] => 123
174+
[foo] => 124
175175
)
176176
177177
)

0 commit comments

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