Pārlūkot izejas kodu

Merge remote branch 'markchalloner/master'

* markchalloner/master:
  [Validator] Updated ContraintViolationList ArrayAccess setter to check equivalence to null instead of using is_null
  Implemented ArrayAccess interface
Fabien Potencier 14 gadi atpakaļ
vecāks
revīzija
0ac679e73c

+ 38 - 1
src/Symfony/Component/Validator/ConstraintViolationList.php

@@ -14,7 +14,7 @@ namespace Symfony\Component\Validator;
 /**
  * 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 @@ EOF;
     {
         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]);
+    }
+    
 }