|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* Copyright (C) 2018 Sebastian Böttger <[email protected]> |
|
4
|
|
|
* You may use, distribute and modify this code under the |
|
5
|
|
|
* terms of the MIT license. |
|
6
|
|
|
* |
|
7
|
|
|
* You should have received a copy of the MIT license with |
|
8
|
|
|
* this file. If not, please visit: https://opensource.org/licenses/mit-license.php |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
namespace Seboettg\Collection\ArrayList; |
|
13
|
|
|
|
|
14
|
|
|
|
|
15
|
|
|
trait ArrayAccessTrait |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* {@inheritDoc} |
|
19
|
|
|
*/ |
|
20
|
|
|
public function getIterator() |
|
21
|
|
|
{ |
|
22
|
|
|
return new \ArrayIterator($this->array); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Offset to retrieve |
|
27
|
|
|
* @link http://php.net/manual/en/arrayaccess.offsetget.php |
|
28
|
|
|
* @param mixed $offset The offset to retrieve. |
|
29
|
|
|
* |
|
30
|
|
|
* @return mixed Can return all value types. |
|
31
|
|
|
*/ |
|
32
|
|
|
public function offsetGet($offset) |
|
33
|
|
|
{ |
|
34
|
|
|
return isset($this->array[$offset]) ? $this->array[$offset] : null; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Offset to set |
|
39
|
|
|
* @link http://php.net/manual/en/arrayaccess.offsetset.php |
|
40
|
|
|
* @param mixed $offset The offset to assign the value to. |
|
41
|
|
|
* @param mixed $value The value to set. |
|
42
|
|
|
*/ |
|
43
|
|
|
public function offsetSet($offset, $value) |
|
44
|
|
|
{ |
|
45
|
|
|
$this->array[$offset] = $value; |
|
|
|
|
|
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Whether a offset exists |
|
50
|
|
|
* @link http://php.net/manual/en/arrayaccess.offsetexists.php |
|
51
|
|
|
* |
|
52
|
|
|
* @param mixed $offset |
|
53
|
|
|
* @return bool |
|
54
|
|
|
*/ |
|
55
|
|
|
public function offsetExists($offset) |
|
56
|
|
|
{ |
|
57
|
|
|
return isset($this->array[$offset]); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Offset to unset |
|
62
|
|
|
* @link http://php.net/manual/en/arrayaccess.offsetunset.php |
|
63
|
|
|
* @param mixed $offset The offset to unset. |
|
64
|
|
|
*/ |
|
65
|
|
|
public function offsetUnset($offset) |
|
66
|
|
|
{ |
|
67
|
|
|
unset($this->array[$offset]); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* {@inheritDoc} |
|
72
|
|
|
*/ |
|
73
|
|
|
public function count() |
|
74
|
|
|
{ |
|
75
|
|
|
return count($this->array); |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|