diff --git a/ConstraintViolationList.php b/ConstraintViolationList.php index 7aedc7b1e..65d5effa9 100644 --- a/ConstraintViolationList.php +++ b/ConstraintViolationList.php @@ -14,7 +14,7 @@ /** * An array-acting object that holds many ConstrainViolation instances. */ -class ConstraintViolationList implements \IteratorAggregate, \Countable +class ConstraintViolationList implements \IteratorAggregate, \Countable, \ArrayAccess { protected $violations = array(); @@ -75,4 +75,41 @@ 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 (is_null($offset)) { + $this->violations[] = $value; + } else { + $this->violations[$offset] = $value; + } + } + + /** + * @see ArrayAccess + */ + public function offsetUnset($offset) + { + unset($this->violations[$offset]); + } + } \ No newline at end of file