Submit
Path:
~
/
/
opt
/
psa
/
admin
/
plib
/
modules
/
wp-toolkit
/
vendor
/
symfony
/
validator
/
DataCollector
/
File Content:
ValidatorDataCollector.php
<?php /* * This file is part of the Symfony package. * * (c) Fabien Potencier <fabien@symfony.com> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace WPToolkitDependenciesIsolationPrefix\Symfony\Component\Validator\DataCollector; use WPToolkitDependenciesIsolationPrefix\Symfony\Component\Form\FormInterface; use WPToolkitDependenciesIsolationPrefix\Symfony\Component\HttpFoundation\Request; use WPToolkitDependenciesIsolationPrefix\Symfony\Component\HttpFoundation\Response; use WPToolkitDependenciesIsolationPrefix\Symfony\Component\HttpKernel\DataCollector\DataCollector; use WPToolkitDependenciesIsolationPrefix\Symfony\Component\HttpKernel\DataCollector\LateDataCollectorInterface; use WPToolkitDependenciesIsolationPrefix\Symfony\Component\Validator\Validator\TraceableValidator; use WPToolkitDependenciesIsolationPrefix\Symfony\Component\VarDumper\Caster\Caster; use WPToolkitDependenciesIsolationPrefix\Symfony\Component\VarDumper\Caster\ClassStub; use WPToolkitDependenciesIsolationPrefix\Symfony\Component\VarDumper\Cloner\Data; use WPToolkitDependenciesIsolationPrefix\Symfony\Component\VarDumper\Cloner\Stub; /** * @author Maxime Steinhausser <maxime.steinhausser@gmail.com> * * @final */ class ValidatorDataCollector extends DataCollector implements LateDataCollectorInterface { public function __construct(private TraceableValidator $validator) { $this->reset(); } public function collect(Request $request, Response $response, ?\Throwable $exception = null) : void { // Everything is collected once, on kernel terminate. } public function reset() : void { $this->data = ['calls' => $this->cloneVar([]), 'violations_count' => 0]; } public function lateCollect() : void { $collected = $this->validator->getCollectedData(); $this->data['calls'] = $this->cloneVar($collected); $this->data['violations_count'] = \array_reduce($collected, fn($previous, $item) => $previous + \count($item['violations']), 0); } public function getCalls() : Data { return $this->data['calls']; } public function getViolationsCount() : int { return $this->data['violations_count']; } public function getName() : string { return 'validator'; } protected function getCasters() : array { return parent::getCasters() + [\Exception::class => function (\Exception $e, array $a, Stub $s) { foreach (["\x00Exception\x00previous", "\x00Exception\x00trace"] as $k) { if (isset($a[$k])) { unset($a[$k]); ++$s->cut; } } return $a; }, FormInterface::class => fn(FormInterface $f, array $a) => [Caster::PREFIX_VIRTUAL . 'name' => $f->getName(), Caster::PREFIX_VIRTUAL . 'type_class' => new ClassStub($f->getConfig()->getType()->getInnerType()::class), Caster::PREFIX_VIRTUAL . 'data' => $f->getData()]]; } }
Submit
FILE
FOLDER
INFO
Name
Size
Permission
Action
ValidatorDataCollector.php
3076 bytes
0644
N4ST4R_ID | Naxtarrr