- md5
- 200856a8abe812311954a3e572cb33bb
- sha1
- 6dd5f55a8c968f9e3cac5cdef52a39f96b5f5ec3
- sha256
- df5515c8362e0af6d795ac939d08d9084705157e4e126feb6a4bc8a0689dc551
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <[email protected]>
*
* 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 <[email protected]>
*
* @final
*/
class ValidatorDataCollector extends DataCollector implements LateDataCollectorInterface
{
private TraceableValidator $validator;
public function __construct(TraceableValidator $validator)
{
$this->validator = $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, static 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 => static function (\Exception $e, array $a, Stub $s) {
foreach (["\0Exception\0previous", "\0Exception\0trace"] as $k) {
if (isset($a[$k])) {
unset($a[$k]);
++$s->cut;
}
}
return $a;
},
FormInterface::class => static 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(),
],
];
}
}
The same content is in 9 releases, Joomla 6.2.0-alpha2 to 6.2.1-rc1. See them all, or every version of this file.