Skip to content

Commit

Permalink
Implemented ArrayAccess interface
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Challoner committed Mar 28, 2011
1 parent 2a730bf commit c210ba1
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion ConstraintViolationList.php
Expand Up @@ -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();

Expand Down Expand Up @@ -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]);
}

}

0 comments on commit c210ba1

Please sign in to comment.