ContextualValidatorInterface.php
4 years ago
LazyProperty.php
4 years ago
RecursiveContextualValidator.php
8 months ago
RecursiveValidator.php
4 years ago
TraceableValidator.php
4 years ago
ValidatorInterface.php
4 years ago
index.php
3 years ago
TraceableValidator.php
72 lines
| 1 | <?php |
| 2 | namespace MailPoetVendor\Symfony\Component\Validator\Validator; |
| 3 | if (!defined('ABSPATH')) exit; |
| 4 | use MailPoetVendor\Symfony\Component\Validator\Context\ExecutionContextInterface; |
| 5 | use MailPoetVendor\Symfony\Contracts\Service\ResetInterface; |
| 6 | class TraceableValidator implements ValidatorInterface, ResetInterface |
| 7 | { |
| 8 | private $validator; |
| 9 | private $collectedData = []; |
| 10 | public function __construct(ValidatorInterface $validator) |
| 11 | { |
| 12 | $this->validator = $validator; |
| 13 | } |
| 14 | public function getCollectedData() |
| 15 | { |
| 16 | return $this->collectedData; |
| 17 | } |
| 18 | public function reset() |
| 19 | { |
| 20 | $this->collectedData = []; |
| 21 | } |
| 22 | public function getMetadataFor($value) |
| 23 | { |
| 24 | return $this->validator->getMetadataFor($value); |
| 25 | } |
| 26 | public function hasMetadataFor($value) |
| 27 | { |
| 28 | return $this->validator->hasMetadataFor($value); |
| 29 | } |
| 30 | public function validate($value, $constraints = null, $groups = null) |
| 31 | { |
| 32 | $violations = $this->validator->validate($value, $constraints, $groups); |
| 33 | $trace = \debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS, 7); |
| 34 | $file = $trace[0]['file']; |
| 35 | $line = $trace[0]['line']; |
| 36 | for ($i = 1; $i < 7; ++$i) { |
| 37 | if (isset($trace[$i]['class'], $trace[$i]['function']) && 'validate' === $trace[$i]['function'] && \is_a($trace[$i]['class'], ValidatorInterface::class, \true)) { |
| 38 | $file = $trace[$i]['file']; |
| 39 | $line = $trace[$i]['line']; |
| 40 | while (++$i < 7) { |
| 41 | if (isset($trace[$i]['function'], $trace[$i]['file']) && empty($trace[$i]['class']) && !\str_starts_with($trace[$i]['function'], 'call_user_func')) { |
| 42 | $file = $trace[$i]['file']; |
| 43 | $line = $trace[$i]['line']; |
| 44 | break; |
| 45 | } |
| 46 | } |
| 47 | break; |
| 48 | } |
| 49 | } |
| 50 | $name = \str_replace('\\', '/', $file); |
| 51 | $name = \substr($name, \strrpos($name, '/') + 1); |
| 52 | $this->collectedData[] = ['caller' => \compact('name', 'file', 'line'), 'context' => \compact('value', 'constraints', 'groups'), 'violations' => \iterator_to_array($violations)]; |
| 53 | return $violations; |
| 54 | } |
| 55 | public function validateProperty(object $object, string $propertyName, $groups = null) |
| 56 | { |
| 57 | return $this->validator->validateProperty($object, $propertyName, $groups); |
| 58 | } |
| 59 | public function validatePropertyValue($objectOrClass, string $propertyName, $value, $groups = null) |
| 60 | { |
| 61 | return $this->validator->validatePropertyValue($objectOrClass, $propertyName, $value, $groups); |
| 62 | } |
| 63 | public function startContext() |
| 64 | { |
| 65 | return $this->validator->startContext(); |
| 66 | } |
| 67 | public function inContext(ExecutionContextInterface $context) |
| 68 | { |
| 69 | return $this->validator->inContext($context); |
| 70 | } |
| 71 | } |
| 72 |