Command
3 years ago
Constraints
3 years ago
Context
3 years ago
Exception
3 years ago
Mapping
3 years ago
Util
3 years ago
Validator
3 years ago
Violation
3 years ago
Constraint.php
4 years ago
ConstraintValidator.php
4 years ago
ConstraintValidatorFactory.php
4 years ago
ConstraintValidatorFactoryInterface.php
4 years ago
ConstraintValidatorInterface.php
4 years ago
ConstraintViolation.php
4 years ago
ConstraintViolationInterface.php
4 years ago
ConstraintViolationList.php
4 years ago
ConstraintViolationListInterface.php
4 years ago
ContainerConstraintValidatorFactory.php
4 years ago
GroupSequenceProviderInterface.php
4 years ago
ObjectInitializerInterface.php
4 years ago
Validation.php
4 years ago
ValidatorBuilder.php
4 years ago
index.php
3 years ago
ConstraintValidator.php
61 lines
| 1 | <?php |
| 2 | namespace MailPoetVendor\Symfony\Component\Validator; |
| 3 | if (!defined('ABSPATH')) exit; |
| 4 | use MailPoetVendor\Symfony\Component\Validator\Context\ExecutionContextInterface; |
| 5 | abstract class ConstraintValidator implements ConstraintValidatorInterface |
| 6 | { |
| 7 | public const PRETTY_DATE = 1; |
| 8 | public const OBJECT_TO_STRING = 2; |
| 9 | protected $context; |
| 10 | public function initialize(ExecutionContextInterface $context) |
| 11 | { |
| 12 | $this->context = $context; |
| 13 | } |
| 14 | protected function formatTypeOf($value) |
| 15 | { |
| 16 | return \get_debug_type($value); |
| 17 | } |
| 18 | protected function formatValue($value, int $format = 0) |
| 19 | { |
| 20 | if ($format & self::PRETTY_DATE && $value instanceof \DateTimeInterface) { |
| 21 | if (\class_exists(\IntlDateFormatter::class)) { |
| 22 | $formatter = new \IntlDateFormatter(\Locale::getDefault(), \IntlDateFormatter::MEDIUM, \IntlDateFormatter::SHORT, 'UTC'); |
| 23 | return $formatter->format(new \DateTime($value->format('Y-m-d H:i:s.u'), new \DateTimeZone('UTC'))); |
| 24 | } |
| 25 | return $value->format('Y-m-d H:i:s'); |
| 26 | } |
| 27 | if (\is_object($value)) { |
| 28 | if ($format & self::OBJECT_TO_STRING && \method_exists($value, '__toString')) { |
| 29 | return $value->__toString(); |
| 30 | } |
| 31 | return 'object'; |
| 32 | } |
| 33 | if (\is_array($value)) { |
| 34 | return 'array'; |
| 35 | } |
| 36 | if (\is_string($value)) { |
| 37 | return '"' . $value . '"'; |
| 38 | } |
| 39 | if (\is_resource($value)) { |
| 40 | return 'resource'; |
| 41 | } |
| 42 | if (null === $value) { |
| 43 | return 'null'; |
| 44 | } |
| 45 | if (\false === $value) { |
| 46 | return 'false'; |
| 47 | } |
| 48 | if (\true === $value) { |
| 49 | return 'true'; |
| 50 | } |
| 51 | return (string) $value; |
| 52 | } |
| 53 | protected function formatValues(array $values, int $format = 0) |
| 54 | { |
| 55 | foreach ($values as $key => $value) { |
| 56 | $values[$key] = $this->formatValue($value, $format); |
| 57 | } |
| 58 | return \implode(', ', $values); |
| 59 | } |
| 60 | } |
| 61 |