ArrayAccessible.php 778 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. class ArrayAccessible implements ArrayAccess, IteratorAggregate
  3. {
  4. private $array;
  5. public function __construct(array $array = [])
  6. {
  7. $this->array = $array;
  8. }
  9. public function offsetExists($offset)
  10. {
  11. return array_key_exists($offset, $this->array);
  12. }
  13. public function offsetGet($offset)
  14. {
  15. return $this->array[$offset];
  16. }
  17. public function offsetSet($offset, $value)
  18. {
  19. if (null === $offset) {
  20. $this->array[] = $value;
  21. } else {
  22. $this->array[$offset] = $value;
  23. }
  24. }
  25. public function offsetUnset($offset)
  26. {
  27. unset($this->array[$offset]);
  28. }
  29. public function getIterator()
  30. {
  31. return new ArrayIterator($this->array);
  32. }
  33. }