* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Validator\DataCollector; use Symfony\Component\Form\FormInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\DataCollector\DataCollector; use Symfony\Component\HttpKernel\DataCollector\LateDataCollectorInterface; 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\Stub; /** * @author Maxime Steinhausser */ class ValidatorDataCollector extends DataCollector implements LateDataCollectorInterface { private $validator; public function __construct(TraceableValidator $validator) { $this->validator = $validator; $this->reset(); } /** * {@inheritdoc} */ public function collect(Request $request, Response $response, \Exception $exception = null) { // Everything is collected once, on kernel terminate. } public function reset() { $this->data = array( 'calls' => $this->cloneVar(array()), 'violations_count' => 0, ); } /** * {@inheritdoc} */ public function lateCollect() { $collected = $this->validator->getCollectedData(); $this->data['calls'] = $this->cloneVar($collected); $this->data['violations_count'] = array_reduce($collected, function ($previous, $item) { return $previous + count($item['violations']); }, 0); } /** * @return Data */ public function getCalls() { return $this->data['calls']; } /** * @return int */ public function getViolationsCount() { return $this->data['violations_count']; } /** * {@inheritdoc} */ public function getName() { return 'validator'; } protected function getCasters() { 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; } } 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(), ); }, ); } } __halt_compiler();----SIGNATURE:----IztSbJ0qabjia4QWzwow02PKoxN1o7yCQubM3EHoT0XUgTTQb2Kpa23Fzqf3w9ddAFBdKtRKJ7M+8ELAY6oGHR67iKru8scmA4Ixh0gy0e2nrU7OF6mhkXNIppqx/TgB4S8++7rX5axPxGcn/ocDCplGGjrrYxQeWpeDFAjXddF7IdsRi2FlBX3z2s9rgPU9Ab3n2JTIk1qoGsfM4Dra0Yb+V6YplbHtyrCjhVdGy+auAh25sUxj4Yv56ijYoxzaGvCX+uzcra12nFuWlOJ/xFnZSNmJPMQiNC0ftwYaBR3oKBOSM8duol2kj1Yq9FG9MyjUS6Dhk1zmtU7On8nLF4joVxvAOh1BgsBpKANukah03IfjlIxKIkS7lf1MOON3BHFN1RYWe8EhkgWWLvJC0rCJEIzgbwmNZtpURS/jhySZK0U5u/0aXtki6UDVVCCoIulF4Os2h6Bvy6FxUS/wYeXpTjQP1luKHgta6dR90yq66G1S804Q7g09okrMrA3/v0etlSJqLjh/6jq6P3nApfOxFNhC3twq/9a+pdxII0Wg7ALaGqnhK961l0EwkiUVk1ZQ5H6IvllnEIOdwq7vaE0MjO1ap1BzSE2TzT1Tbfiy2QsksC62ey+F9w0uEl26CvqP8V3tcOqLoa/zBNS4yt0BROC9GPEmEN0XoaLo0Uw=----ATTACHMENT:----MjkxOTE5NDkzMDE5NDg1NSA1MTQxMTQ0MzYzMDQ4MDYwIDI1NDg1MjQzMTM5NzU1MA==