ConstraintViolationList.php in Plug 7
File
lib/Symfony/validator/Symfony/Component/Validator/ConstraintViolationList.php
View source
<?php
namespace Symfony\Component\Validator;
class ConstraintViolationList implements \IteratorAggregate, ConstraintViolationListInterface {
private $violations = array();
public function __construct(array $violations = array()) {
foreach ($violations as $violation) {
$this
->add($violation);
}
}
public function __toString() {
$string = '';
foreach ($this->violations as $violation) {
$string .= $violation . "\n";
}
return $string;
}
public function add(ConstraintViolationInterface $violation) {
$this->violations[] = $violation;
}
public function addAll(ConstraintViolationListInterface $otherList) {
foreach ($otherList as $violation) {
$this->violations[] = $violation;
}
}
public function get($offset) {
if (!isset($this->violations[$offset])) {
throw new \OutOfBoundsException(sprintf('The offset "%s" does not exist.', $offset));
}
return $this->violations[$offset];
}
public function has($offset) {
return isset($this->violations[$offset]);
}
public function set($offset, ConstraintViolationInterface $violation) {
$this->violations[$offset] = $violation;
}
public function remove($offset) {
unset($this->violations[$offset]);
}
public function getIterator() {
return new \ArrayIterator($this->violations);
}
public function count() {
return count($this->violations);
}
public function offsetExists($offset) {
return $this
->has($offset);
}
public function offsetGet($offset) {
return $this
->get($offset);
}
public function offsetSet($offset, $violation) {
if (null === $offset) {
$this
->add($violation);
}
else {
$this
->set($offset, $violation);
}
}
public function offsetUnset($offset) {
$this
->remove($offset);
}
}