SampleArrayAccess.php (906B)
1 <?php 2 /** 3 * Sample class that implements ArrayAccess copied from 4 * http://www.php.net/manual/en/class.arrayaccess.php 5 * with some minor changes 6 * This class required for PHPUnit_Framework_Constraint_ArrayHasKey testing 7 */ 8 9 class SampleArrayAccess implements ArrayAccess 10 { 11 private $container; 12 13 public function __construct() { 14 $this->container = array(); 15 } 16 public function offsetSet($offset, $value) { 17 if (is_null($offset)) { 18 $this->container[] = $value; 19 } else { 20 $this->container[$offset] = $value; 21 } 22 } 23 public function offsetExists($offset) { 24 return isset($this->container[$offset]); 25 } 26 public function offsetUnset($offset) { 27 unset($this->container[$offset]); 28 } 29 public function offsetGet($offset) { 30 return isset($this->container[$offset]) ? $this->container[$offset] : null; 31 } 32 }