|
24 | 24 | * // Number: 0
|
25 | 25 | * ```
|
26 | 26 | *
|
27 |
| - * @todo implement Iterator, Countable, ArrayAccess interfaces |
| 27 | + * @todo implement Iterator, Countable interfaces |
28 | 28 | *
|
29 | 29 | * @package sclable\arrayFunctions
|
30 | 30 | * @author Michael Rutz <[email protected]>
|
|
34 | 34 | * @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
|
35 | 35 | *
|
36 | 36 | */
|
37 |
| -class ArrayWrap |
| 37 | +class ArrayWrap implements \ArrayAccess |
38 | 38 | {
|
39 | 39 | /**
|
40 | 40 | * the raw array data container
|
@@ -104,6 +104,53 @@ protected function reply(array $data)
|
104 | 104 | return static::create($data);
|
105 | 105 | }
|
106 | 106 |
|
| 107 | + /** |
| 108 | + * Whether a offset exists |
| 109 | + * @link http://php.net/manual/en/arrayaccess.offsetexists.php |
| 110 | + * @param mixed $offset An offset to check for. |
| 111 | + * @return boolean true on success or false on failure. |
| 112 | + * The return value will be casted to boolean if non-boolean was returned. |
| 113 | + */ |
| 114 | + public function offsetExists($offset) |
| 115 | + { |
| 116 | + return $this->hasKey($offset); |
| 117 | + } |
| 118 | + |
| 119 | + /** |
| 120 | + * Offset to retrieve |
| 121 | + * @link http://php.net/manual/en/arrayaccess.offsetget.php |
| 122 | + * @param mixed $offset The offset to retrieve. |
| 123 | + * @return mixed Can return all value types. |
| 124 | + */ |
| 125 | + public function offsetGet($offset) |
| 126 | + { |
| 127 | + return $this->hasKey($offset) ? $this->data[$offset] : null; |
| 128 | + } |
| 129 | + |
| 130 | + /** |
| 131 | + * Offset to set |
| 132 | + * @link http://php.net/manual/en/arrayaccess.offsetset.php |
| 133 | + * @param mixed $offset The offset to assign the value to. |
| 134 | + * @param mixed $value The value to set. |
| 135 | + * @return void |
| 136 | + */ |
| 137 | + public function offsetSet($offset, $value) |
| 138 | + { |
| 139 | + $this->data[$offset] = $value; |
| 140 | + } |
| 141 | + |
| 142 | + /** |
| 143 | + * Offset to unset |
| 144 | + * @link http://php.net/manual/en/arrayaccess.offsetunset.php |
| 145 | + * @param mixed $offset The offset to unset. |
| 146 | + * @return void |
| 147 | + */ |
| 148 | + public function offsetUnset($offset) |
| 149 | + { |
| 150 | + unset($this->data[$offset]); |
| 151 | + } |
| 152 | + |
| 153 | + |
107 | 154 | /**
|
108 | 155 | * Pad the array to the specified length with a value
|
109 | 156 | * @see array_pad()
|
|
0 commit comments