Command
2 years ago
Constraints
1 year ago
Context
1 year ago
Exception
3 years ago
Mapping
6 months ago
Util
3 years ago
Validator
8 months ago
Violation
3 years ago
Constraint.php
1 year ago
ConstraintValidator.php
2 years ago
ConstraintValidatorFactory.php
4 years ago
ConstraintValidatorFactoryInterface.php
4 years ago
ConstraintValidatorInterface.php
4 years ago
ConstraintViolation.php
1 year 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
ConstraintViolationList.php
102 lines
| 1 | <?php |
| 2 | namespace MailPoetVendor\Symfony\Component\Validator; |
| 3 | if (!defined('ABSPATH')) exit; |
| 4 | class ConstraintViolationList implements \IteratorAggregate, ConstraintViolationListInterface |
| 5 | { |
| 6 | private $violations = []; |
| 7 | public function __construct(iterable $violations = []) |
| 8 | { |
| 9 | foreach ($violations as $violation) { |
| 10 | $this->add($violation); |
| 11 | } |
| 12 | } |
| 13 | public static function createFromMessage(string $message) : self |
| 14 | { |
| 15 | $self = new self(); |
| 16 | $self->add(new ConstraintViolation($message, '', [], null, '', null)); |
| 17 | return $self; |
| 18 | } |
| 19 | public function __toString() |
| 20 | { |
| 21 | $string = ''; |
| 22 | foreach ($this->violations as $violation) { |
| 23 | $string .= $violation . "\n"; |
| 24 | } |
| 25 | return $string; |
| 26 | } |
| 27 | public function add(ConstraintViolationInterface $violation) |
| 28 | { |
| 29 | $this->violations[] = $violation; |
| 30 | } |
| 31 | public function addAll(ConstraintViolationListInterface $otherList) |
| 32 | { |
| 33 | foreach ($otherList as $violation) { |
| 34 | $this->violations[] = $violation; |
| 35 | } |
| 36 | } |
| 37 | public function get(int $offset) |
| 38 | { |
| 39 | if (!isset($this->violations[$offset])) { |
| 40 | throw new \OutOfBoundsException(\sprintf('The offset "%s" does not exist.', $offset)); |
| 41 | } |
| 42 | return $this->violations[$offset]; |
| 43 | } |
| 44 | public function has(int $offset) |
| 45 | { |
| 46 | return isset($this->violations[$offset]); |
| 47 | } |
| 48 | public function set(int $offset, ConstraintViolationInterface $violation) |
| 49 | { |
| 50 | $this->violations[$offset] = $violation; |
| 51 | } |
| 52 | public function remove(int $offset) |
| 53 | { |
| 54 | unset($this->violations[$offset]); |
| 55 | } |
| 56 | #[\ReturnTypeWillChange] |
| 57 | public function getIterator() |
| 58 | { |
| 59 | return new \ArrayIterator($this->violations); |
| 60 | } |
| 61 | #[\ReturnTypeWillChange] |
| 62 | public function count() |
| 63 | { |
| 64 | return \count($this->violations); |
| 65 | } |
| 66 | #[\ReturnTypeWillChange] |
| 67 | public function offsetExists($offset) |
| 68 | { |
| 69 | return $this->has($offset); |
| 70 | } |
| 71 | #[\ReturnTypeWillChange] |
| 72 | public function offsetGet($offset) |
| 73 | { |
| 74 | return $this->get($offset); |
| 75 | } |
| 76 | #[\ReturnTypeWillChange] |
| 77 | public function offsetSet($offset, $violation) |
| 78 | { |
| 79 | if (null === $offset) { |
| 80 | $this->add($violation); |
| 81 | } else { |
| 82 | $this->set($offset, $violation); |
| 83 | } |
| 84 | } |
| 85 | #[\ReturnTypeWillChange] |
| 86 | public function offsetUnset($offset) |
| 87 | { |
| 88 | $this->remove($offset); |
| 89 | } |
| 90 | public function findByCodes($codes) |
| 91 | { |
| 92 | $codes = (array) $codes; |
| 93 | $violations = []; |
| 94 | foreach ($this as $violation) { |
| 95 | if (\in_array($violation->getCode(), $codes, \true)) { |
| 96 | $violations[] = $violation; |
| 97 | } |
| 98 | } |
| 99 | return new static($violations); |
| 100 | } |
| 101 | } |
| 102 |