* * 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:----ixzSoz4n3Sdt5ozKqFCWOFKlBZDLW3YnBRF/pFogha70HiefTIVNm/uTB56aHq1kvrX9/gSAXizcpnkDj1ORYh4T+QCR3mz0LsV/nXeg3NZvreWm6uPEzqKlCtdmBrx1BGtWBcqFT2mRHAiPfGQZdPo4qE+JUhKVrvQwBgXMxsKXcRFslQkBBFA2tRdhpAlEs5MVuhLB9cfA/DG9kQvUaR48IJRFLwkkpxJ29pqHr0cMMBoHBGixKIQQQEXQqH4agzC8McsTSiUlKHrKSYYfnwIzw8b9IyP+32nKKsVSUAYtF1clugMi8JnWKFtHyCShoR7qVOwFr/fi1BWAo8iQKW1GLwDlRe2nr9yXama9pz+pRMP7SZlE8vhEQkgXy+ZqwNLVzJxWvkwtNIoXwFoQH0j1wUSZHKaNmS5hlj1L39xswpZMHoKr2pb53uSFxUmg1xFbFsuGCC+kFgoy/2IuIu0EhrmERHGCa+UP6a3Ca5VmKHGQ7FyqGyneNyrApfd+RBLMvgSSshwaSsmuSWE/s/WSJX2JsZgpqhLNTcPMuRF9ZGUJsoaTNYa7ndXb+u+4qG5oUZaSmfBXWThdjZFNY1QMkz4kBHixGDAz+iOACN4DcI6/HOEvGiqyJIc7OOr/0idlMiWPgqBpDgeynUuKR12z4yNaM/yog2jUjjXcXL4=----ATTACHMENT:----NjkwODQ5NzI0MTAwOTE4MyA3MDQ3NDE3MDU0ODcyMjg2IDY4MjI3MjY1OTI1NDg4NTE=