Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2eff192

Browse files
committed
feature #19987 [VarDumper] Use ClassStub for reflected types (nicolas-grekas)
This PR was merged into the 3.2-dev branch. Discussion ---------- [VarDumper] Use ClassStub for reflected types | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - The implementation ensures that type hints do not trigger autoloading by `ClassStub` itself. Commits ------- e2b2c9b [VarDumper] Use ClassStub for reflected types
2 parents da3ff6c + e2b2c9b commit 2eff192

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/Symfony/Component/VarDumper/Caster/ReflectionCaster.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,11 @@ public static function castFunctionAbstract(\ReflectionFunctionAbstract $c, arra
157157
));
158158

159159
if (isset($a[$prefix.'returnType'])) {
160-
$a[$prefix.'returnType'] = (string) $a[$prefix.'returnType'];
160+
$v = (string) $a[$prefix.'returnType'];
161+
$a[$prefix.'returnType'] = new ClassStub($v, array(class_exists($v, false) || interface_exists($v, false) || trait_exists($v, false) ? $v : '', ''));
162+
}
163+
if (isset($a[$prefix.'class'])) {
164+
$a[$prefix.'class'] = new ClassStub($a[$prefix.'class']);
161165
}
162166
if (isset($a[$prefix.'this'])) {
163167
$a[$prefix.'this'] = new CutStub($a[$prefix.'this']);
@@ -231,6 +235,10 @@ public static function castParameter(\ReflectionParameter $c, array $a, Stub $st
231235
$a[$prefix.'typeHint'] = $m[1];
232236
}
233237
}
238+
if (isset($a[$prefix.'typeHint'])) {
239+
$v = $a[$prefix.'typeHint'];
240+
$a[$prefix.'typeHint'] = new ClassStub($v, array(class_exists($v, false) || interface_exists($v, false) || trait_exists($v, false) ? $v : '', ''));
241+
}
234242

235243
try {
236244
$a[$prefix.'default'] = $v = $c->getDefaultValue();

src/Symfony/Component/VarDumper/Tests/HtmlDumperTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ public function testGet()
7575
+"<span class=sf-dump-public title="Runtime added dynamic property">bar</span>": "<span class=sf-dump-str title="3 characters">bar</span>"
7676
</samp>}
7777
"<span class=sf-dump-key>closure</span>" => <span class=sf-dump-note>Closure</span> {{$r}<samp>
78-
<span class=sf-dump-meta>class</span>: "<span class=sf-dump-str title="48 characters">Symfony\Component\VarDumper\Tests\HtmlDumperTest</span>"
78+
<span class=sf-dump-meta>class</span>: "<span class=sf-dump-str title="Symfony\Component\VarDumper\Tests\HtmlDumperTest
79+
48 characters"><span class=sf-dump-ellipsis>Symfony\Component\VarDumper\Tests</span>\HtmlDumperTest</span>"
7980
<span class=sf-dump-meta>this</span>: <abbr title="Symfony\Component\VarDumper\Tests\HtmlDumperTest" class=sf-dump-note>HtmlDumperTest</abbr> {{$r} &%s;}
8081
<span class=sf-dump-meta>parameters</span>: {<samp>
8182
<span class=sf-dump-meta>\$a</span>: {}

0 commit comments

Comments
 (0)