8000 [Profiler][Validator] ValidatorDataCollector: use new DataCollector::getCasters() method by ogizanagi · Pull Request #23517 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Profiler][Validator] ValidatorDataCollector: use new DataCollector::getCasters() method #23517

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[Profiler][Validator] ValidatorDataCollector: use new DataCollector::…
…getCasters() method
  • Loading branch information
ogizanagi committed Jul 15, 2017
commit c725a700cf2452443b75db48832f28a9cab86e6b
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,14 @@
use Symfony\Component\Validator\Validator\TraceableValidator;
use Symfony\Component\VarDumper\Caster\Caster;
use Symfony\Component\VarDumper\Caster\ClassStub;
use Symfony\Component\VarDumper\Cloner\Data;
use Symfony\Component\VarDumper\Cloner\VarCloner;
use Symfony\Component\VarDumper\Cloner\Stub;

/**
* @author Maxime Steinhausser <maxime.steinhausser@gmail.com>
*/
class ValidatorDataCollector extends DataCollector implements LateDataCollectorInterface
{
private $validator;
private $cloner;

public function __construct(TraceableValidator $validator)
{
Expand Down Expand Up @@ -77,29 +75,26 @@ public function getName()
return 'validator';
}

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

if (null === $this->cloner) {
$this->cloner = new VarCloner();
$this->cloner->setMaxItems(-1);
$this->cloner->addCasters(array(
FormInterface::class => function (FormInterface $f, array $a) {
return array(
Caster::PREFIX_VIRTUAL.'name' => $f->getName(),
Caster::PREFIX_VIRTUAL.'type_class' => new ClassStub(get_class($f->getConfig()->getType()->getInnerType())),
Caster::PREFIX_VIRTUAL.'data' => $f->getData(),
);
},
));
}

return $this->cloner->cloneVar($var, Caster::EXCLUDE_VERBOSE);
return $a;
},
FormInterface::class => function (FormInterface $f, array $a) {
return array(
Caster::PREFIX_VIRTUAL.'name' => $f->getName(),
Caster::PREFIX_VIRTUAL.'type_class' => new ClassStub(get_class($f->getConfig()->getType()->getInnerType())),
Caster::PREFIX_VIRTUAL.'data' => $f->getData(),
);
},
);
}
}
5 changes: 3 additions & 2 deletions src/Symfony/Component/Validator/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
},
"require-dev": {
"symfony/http-foundation": "~2.8|~3.0|~4.0",
"symfony/http-kernel": "~2.8|~3.0|~4.0.0",
"symfony/var-dumper": "~3.3|~4.0.0",
"symfony/http-kernel": "^3.3.5|~4.0",
"symfony/var-dumper": "~3.3|~4.0",
"symfony/intl": "^2.8.18|^3.2.5|~4.0",
"symfony/yaml": "~3.3|~4.0",
"symfony/config": "~2.8|~3.0|~4.0",
Expand All @@ -38,6 +38,7 @@
"conflict": {
"phpunit/phpunit": "<4.8.35|<5.4.3,>=5.0",
"symfony/dependency-injection": "<3.3",
"symfony/http-kernel": "<3.3.5",
"symfony/yaml": "<3.3"
},
"suggest": {
Expand Down
0