Skip to content

Commit dbf98b8

Browse files
Use ClassStub & LinkStub wrappers
1 parent 541223e commit dbf98b8

File tree

4 files changed

+51
-14
lines changed

4 files changed

+51
-14
lines changed

src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/form.html.twig

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,6 @@
152152
margin-top: -9px;
153153
margin-left: 6px;
154154
}
155-
.form-type {
156-
color: #999;
157-
}
158155
.badge-error {
159156
float: right;
160157
background: #B0413E;
@@ -442,7 +439,7 @@
442439
{% endif %}
443440

444441
<span {% if has_error or data.has_children_error|default(false) %}class="has-error"{% endif %}>
445-
{{ name|default('(no name)') }} {% if data.type_class is defined %}[<abbr title="{{ data.type_class }}">{{ data.type_class|split('\\')|last }}</abbr>]{% endif %}
442+
{{ name|default('(no name)') }} [{{ profiler_dump(data.type_class) }}]
446443
</span>
447444
</div>
448445

@@ -460,10 +457,7 @@
460457
{% import _self as tree %}
461458
<div class="tree-details" {% if data.id is defined %}id="{{ data.id }}-details"{% endif %}>
462459
<h2>
463-
{{ name|default('(no name)') }}
464-
{% if data.type_class is defined and data.type is defined %}
465-
<span class="form-type">[<abbr title="{{ data.type_class }}">{{ data.type }}</abbr>]</span>
466-
{% endif %}
460+
{{ name|default('(no name)') }} [{{ profiler_dump(data.type_class) }}]
467461
</h2>
468462

469463
{% if data.errors is defined and data.errors|length > 0 %}

src/Symfony/Component/Form/Extension/DataCollector/FormDataExtractor.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
use Symfony\Component\HttpKernel\DataCollector\Util\ValueExporter;
1717
use Symfony\Component\Validator\ConstraintViolationInterface;
1818
use Symfony\Component\VarDumper\Caster\Caster;
19+
use Symfony\Component\VarDumper\Caster\ClassStub;
20+
use Symfony\Component\VarDumper\Caster\StubCaster;
1921
use Symfony\Component\VarDumper\Cloner\Data;
2022
use Symfony\Component\VarDumper\Cloner\Stub;
2123
use Symfony\Component\VarDumper\Cloner\VarCloner;
@@ -50,7 +52,7 @@ public function extractConfiguration(FormInterface $form)
5052
$data = array(
5153
'id' => $this->buildId($form),
5254
'name' => $form->getName(),
53-
'type_class' => get_class($form->getConfig()->getType()->getInnerType()),
55+
'type_class' => new ClassStub(get_class($form->getConfig()->getType()->getInnerType())),
5456
'synchronized' => $this->cloneVar($form->isSynchronized()),
5557
'passed_options' => array(),
5658
'resolved_options' => array(),
@@ -211,6 +213,9 @@ private function cloneVar($var)
211213
if (null === $this->cloner) {
212214
$this->cloner = new VarCloner();
213215
$this->cloner->addCasters(array(
216+
Stub::class => function (Stub $v, array $a, Stub $s, $isNested) {
217+
return $isNested ? $a : StubCaster::castStub($v, $a, $s, true);
218+
},
214219
\Exception::class => function (\Exception $e, array $a, Stub $s) {
215220
if (isset($a[$k = "\0Exception\0previous"])) {
216221
unset($a[$k]);
@@ -219,13 +224,13 @@ private function cloneVar($var)
219224

220225
return $a;
221226
},
222-
FormInterface::class => function (FormInterface $f, array $a, Stub $s) {
227+
FormInterface::class => function (FormInterface $f, array $a) {
223228
return array(
224229
Caster::PREFIX_VIRTUAL.'name' => $f->getName(),
225-
Caster::PREFIX_VIRTUAL.'type_class' => get_class($f->getConfig()->getType()->getInnerType()),
230+
Caster::PREFIX_VIRTUAL.'type_class' => new ClassStub(get_class($f->getConfig()->getType()->getInnerType())),
226231
);
227232
},
228-
ConstraintViolationInterface::class => function (ConstraintViolationInterface $v, array $a, Stub $stub) {
233+
ConstraintViolationInterface::class => function (ConstraintViolationInterface $v, array $a) {
229234
return array(
230235
Caster::PREFIX_VIRTUAL.'root' => $v->getRoot(),
231236
Caster::PREFIX_VIRTUAL.'path' => $v->getPropertyPath(),

src/Symfony/Component/HttpKernel/DataCollector/DataCollector.php

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,12 @@
1212
namespace Symfony\Component\HttpKernel\DataCollector;
1313

1414
use Symfony\Component\HttpKernel\DataCollector\Util\ValueExporter;
15+
use Symfony\Component\VarDumper\Caster\ClassStub;
16+
use Symfony\Component\VarDumper\Caster\LinkStub;
17+
use Symfony\Component\VarDumper\Caster\StubCaster;
1518
use Symfony\Component\VarDumper\Cloner\ClonerInterface;
1619
use Symfony\Component\VarDumper\Cloner\Data;
20+
use Symfony\Component\VarDumper\Cloner\Stub;
1721
use Symfony\Component\VarDumper\Cloner\VarCloner;
1822

1923
/**
@@ -62,9 +66,14 @@ protected function cloneVar($var)
6266
{
6367
if (null === $this->cloner) {
6468
$this->cloner = new VarCloner();
69+
$this->cloner->addCasters(array(
70+
Stub::class => function (Stub $v, array $a, Stub $s, $isNested) {
71+
return $isNested ? $a : StubCaster::castStub($v, $a, $s, true);
72+
},
73+
));
6574
}
6675

67-
return $this->cloner->cloneVar($var);
76+
return $this->cloner->cloneVar($this->decorateVar($var));
6877
}
6978

7079
/**
@@ -86,4 +95,33 @@ protected function varToString($var)
8695

8796
return $this->valueExporter->exportValue($var);
8897
}
98+
99+
private function decorateVar($var)
100+
{
101+
if (is_array($var)) {
102+
if (isset($var[0], $var[1]) && is_callable($var)) {
103+
return ClassStub::wrapCallable($var);
104+
}
105+
foreach ($var as $k => $v) {
106+
if ($v !== $d = $this->decorateVar($v)) {
107+
$var[$k] = $d;
108+
}
109+
}
110+
111+
return $var;
112+
}
113+
if (is_string($var)) {
114+
if (false !== strpos($var, '\\')) {
115+
$c = (false !== $i = strpos($var, '::')) ? substr($var, 0, $i) : $var;
116+
if (class_exists($c, false) || interface_exists($c, false) || trait_exists($c, false)) {
117+
return new ClassStub($var);
118+
}
119+
}
120+
if (false !== strpos($var, DIRECTORY_SEPARATOR) && file_exists($var)) {
121+
return new LinkStub($var);
122+
}
123+
}
124+
125+
return $var;
126+
}
89127
}

src/Symfony/Component/HttpKernel/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"symfony/event-dispatcher": "~2.8|~3.0",
2121
"symfony/http-foundation": "~2.8.8|~3.0.8|~3.1.2|~3.2",
2222
"symfony/debug": "~2.8|~3.0",
23-
"symfony/var-dumper": "~2.8.9|~3.0.9|~3.1.3|~3.2",
23+
"symfony/var-dumper": "~3.2",
2424
"psr/log": "~1.0"
2525
},
2626
"require-dev": {

0 commit comments

Comments
 (0)