ConstraintViolationList.php 1019 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace Symfony\Components\Validator;
  3. class ConstraintViolationList implements \IteratorAggregate, \Countable
  4. {
  5. protected $violations = array();
  6. public function __toString()
  7. {
  8. $string = '';
  9. foreach ($this->violations as $violation) {
  10. $root = $violation->getRoot();
  11. $class = is_object($root) ? get_class($root) : $root;
  12. $string .= <<<EOF
  13. {$class}.{$violation->getPropertyPath()}:
  14. {$violation->getMessage()}
  15. EOF;
  16. }
  17. return $string;
  18. }
  19. public function add(ConstraintViolation $violation)
  20. {
  21. $this->violations[] = $violation;
  22. }
  23. public function addAll(ConstraintViolationList $violations)
  24. {
  25. foreach ($violations->violations as $violation) {
  26. $this->violations[] = $violation;
  27. }
  28. }
  29. public function getIterator()
  30. {
  31. return new \ArrayIterator($this->violations);
  32. }
  33. public function count()
  34. {
  35. return count($this->violations);
  36. }
  37. }