123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- <?php
- /*
- * This file is part of the Symfony package.
- *
- * (c) Fabien Potencier <fabien@symfony.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
- namespace Symfony\Component\Validator;
- /**
- * An array-acting object that holds many ConstrainViolation instances.
- */
- class ConstraintViolationList implements \IteratorAggregate, \Countable, \ArrayAccess
- {
- protected $violations = array();
- /**
- * @return string
- */
- public function __toString()
- {
- $string = '';
- foreach ($this->violations as $violation) {
- $root = $violation->getRoot();
- $class = is_object($root) ? get_class($root) : $root;
- $string .= <<<EOF
- {$class}.{$violation->getPropertyPath()}:
- {$violation->getMessage()}
- EOF;
- }
- return $string;
- }
- /**
- * Add a ConstraintViolation to this list.
- *
- * @param ConstraintViolation $violation
- */
- public function add(ConstraintViolation $violation)
- {
- $this->violations[] = $violation;
- }
- /**
- * Merge an existing ConstraintViolationList into this list.
- *
- * @param ConstraintViolationList $violations
- */
- public function addAll(ConstraintViolationList $violations)
- {
- foreach ($violations->violations as $violation) {
- $this->violations[] = $violation;
- }
- }
- /**
- * @see IteratorAggregate
- */
- public function getIterator()
- {
- return new \ArrayIterator($this->violations);
- }
- /**
- * @see Countable
- */
- public function count()
- {
- return count($this->violations);
- }
- /**
- * @see ArrayAccess
- */
- public function offsetExists($offset)
- {
- return isset($this->violations[$offset]);
- }
- /**
- * @see ArrayAccess
- */
- public function offsetGet($offset)
- {
- return isset($this->violations[$offset]) ? $this->violations[$offset] : null;
- }
- /**
- * @see ArrayAccess
- */
- public function offsetSet($offset, $value)
- {
- if (null === $offset) {
- $this->violations[] = $value;
- } else {
- $this->violations[$offset] = $value;
- }
- }
- /**
- * @see ArrayAccess
- */
- public function offsetUnset($offset)
- {
- unset($this->violations[$offset]);
- }
-
- }
|