Skip to content

Commit 682c458

Browse files
committed
[Profiler][Validator] ValidatorDataCollector: use new DataCollector::getCasters() method
1 parent 0154b2c commit 682c458

File tree

2 files changed

+23
-27
lines changed

2 files changed

+23
-27
lines changed

DataCollector/ValidatorDataCollector.php

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,14 @@
1919
use Symfony\Component\Validator\Validator\TraceableValidator;
2020
use Symfony\Component\VarDumper\Caster\Caster;
2121
use Symfony\Component\VarDumper\Caster\ClassStub;
22-
use Symfony\Component\VarDumper\Cloner\Data;
23-
use Symfony\Component\VarDumper\Cloner\VarCloner;
22+
use Symfony\Component\VarDumper\Cloner\Stub;
2423

2524
/**
2625
* @author Maxime Steinhausser <[email protected]>
2726
*/
2827
class ValidatorDataCollector extends DataCollector implements LateDataCollectorInterface
2928
{
3029
private $validator;
31-
private $cloner;
3230

3331
public function __construct(TraceableValidator $validator)
3432
{
@@ -77,29 +75,26 @@ public function getName()
7775
return 'validator';
7876
}
7977

80-
/**
81-
* {@inheritdoc}
82-
*/
83-
protected function cloneVar($var)
78+
protected function getCasters()
8479
{
85-
if ($var instanceof Data) {
86-
return $var;
87-
}
80+
return parent::getCasters() + array(
81+
\Exception::class => function (\Exception $e, array $a, Stub $s) {
82+
foreach (array("\0Exception\0previous", "\0Exception\0trace") as $k) {
83+
if (isset($a[$k])) {
84+
unset($a[$k]);
85+
++$s->cut;
86+
}
87+
}
8888

89-
if (null === $this->cloner) {
90-
$this->cloner = new VarCloner();
91-
$this->cloner->setMaxItems(-1);
92-
$this->cloner->addCasters(array(
93-
FormInterface::class => function (FormInterface $f, array $a) {
94-
return array(
95-
Caster::PREFIX_VIRTUAL.'name' => $f->getName(),
96-
Caster::PREFIX_VIRTUAL.'type_class' => new ClassStub(get_class($f->getConfig()->getType()->getInnerType())),
97-
Caster::PREFIX_VIRTUAL.'data' => $f->getData(),
98-
);
99-
},
100-
));
101-
}
102-
103-
return $this->cloner->cloneVar($var, Caster::EXCLUDE_VERBOSE);
89+
return $a;
90+
},
91+
FormInterface::class => function (FormInterface $f, array $a) {
92+
return array(
93+
Caster::PREFIX_VIRTUAL.'name' => $f->getName(),
94+
Caster::PREFIX_VIRTUAL.'type_class' => new ClassStub(get_class($f->getConfig()->getType()->getInnerType())),
95+
Caster::PREFIX_VIRTUAL.'data' => $f->getData(),
96+
);
97+
},
98+
);
10499
}
105100
}

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
},
2323
"require-dev": {
2424
"symfony/http-foundation": "~2.8|~3.0|~4.0",
25-
"symfony/http-kernel": "~2.8|~3.0|~4.0.0",
26-
"symfony/var-dumper": "~3.3|~4.0.0",
25+
"symfony/http-kernel": "^3.3.5|~4.0",
26+
"symfony/var-dumper": "~3.3|~4.0",
2727
"symfony/intl": "^2.8.18|^3.2.5|~4.0",
2828
"symfony/yaml": "~3.3|~4.0",
2929
"symfony/config": "~2.8|~3.0|~4.0",
@@ -38,6 +38,7 @@
3838
"conflict": {
3939
"phpunit/phpunit": "<4.8.35|<5.4.3,>=5.0",
4040
"symfony/dependency-injection": "<3.3",
41+
"symfony/http-kernel": "<3.3.5",
4142
"symfony/yaml": "<3.3"
4243
},
4344
"suggest": {

0 commit comments

Comments
 (0)