- md5
- 327f106c1c831f66480b2fad28d94e2c
- sha1
- b3af9ecd7d8b7aa6df319bf3cce3d2942685db48
- sha256
- 22b722f56c7c0bad2e0544eb44749f019c014ec985ca1992eae787988dbb1aa0
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
<?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\Validator;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\Constraints\GroupSequence;
use Symfony\Component\Validator\ConstraintViolationListInterface;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
use Symfony\Component\Validator\Mapping\MetadataInterface;
use Symfony\Contracts\Service\ResetInterface;
/**
* Collects some data about validator calls.
*
* @author Maxime Steinhausser <[email protected]>
*/
class TraceableValidator implements ValidatorInterface, ResetInterface
{
private ValidatorInterface $validator;
private array $collectedData = [];
public function __construct(ValidatorInterface $validator)
{
$this->validator = $validator;
}
public function getCollectedData(): array
{
return $this->collectedData;
}
/**
* @return void
*/
public function reset()
{
$this->collectedData = [];
}
public function getMetadataFor(mixed $value): MetadataInterface
{
return $this->validator->getMetadataFor($value);
}
public function hasMetadataFor(mixed $value): bool
{
return $this->validator->hasMetadataFor($value);
}
public function validate(mixed $value, Constraint|array|null $constraints = null, string|GroupSequence|array|null $groups = null): ConstraintViolationListInterface
{
$violations = $this->validator->validate($value, $constraints, $groups);
$trace = debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS, 7);
$file = $trace[0]['file'];
$line = $trace[0]['line'];
for ($i = 1; $i < 7; ++$i) {
if (isset($trace[$i]['class'], $trace[$i]['function'])
&& 'validate' === $trace[$i]['function']
&& is_a($trace[$i]['class'], ValidatorInterface::class, true)
) {
$file = $trace[$i]['file'];
$line = $trace[$i]['line'];
while (++$i < 7) {
if (isset($trace[$i]['function'], $trace[$i]['file']) && empty($trace[$i]['class']) && !str_starts_with($trace[$i]['function'], 'call_user_func')) {
$file = $trace[$i]['file'];
$line = $trace[$i]['line'];
break;
}
}
break;
}
}
$name = str_replace('\\', '/', $file);
$name = substr($name, strrpos($name, '/') + 1);
$this->collectedData[] = [
'caller' => compact('name', 'file', 'line'),
'context' => compact('value', 'constraints', 'groups'),
'violations' => iterator_to_array($violations),
];
return $violations;
}
public function validateProperty(object $object, string $propertyName, string|GroupSequence|array|null $groups = null): ConstraintViolationListInterface
{
return $this->validator->validateProperty($object, $propertyName, $groups);
}
public function validatePropertyValue(object|string $objectOrClass, string $propertyName, mixed $value, string|GroupSequence|array|null $groups = null): ConstraintViolationListInterface
{
return $this->validator->validatePropertyValue($objectOrClass, $propertyName, $value, $groups);
}
public function startContext(): ContextualValidatorInterface
{
return $this->validator->startContext();
}
public function inContext(ExecutionContextInterface $context): ContextualValidatorInterface
{
return $this->validator->inContext($context);
}
}
The same content is in 136 releases, Joomla 5.1.0-beta1 to 6.3.0-alpha1. See them all, or every version of this file.