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
|
|
|
namespace Seboettg\Collection\ArrayList; |
12
|
|
|
|
13
|
|
|
use ArrayIterator; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Trait ArrayAccessTrait |
17
|
|
|
* @package Seboettg\Collection\ArrayList |
18
|
|
|
* @property $array Base array of this data structure |
19
|
|
|
*/ |
|
|
|
|
20
|
|
|
trait ArrayAccessTrait |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* {@inheritDoc} |
24
|
|
|
*/ |
25
|
|
|
public function getIterator() |
26
|
|
|
{ |
27
|
|
|
return new ArrayIterator($this->array); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Offset to retrieve |
32
|
|
|
* @link http://php.net/manual/en/arrayaccess.offsetget.php |
33
|
|
|
* @param mixed $offset The offset to retrieve. |
34
|
|
|
* |
35
|
|
|
* @return mixed Can return all value types. |
36
|
|
|
*/ |
37
|
|
|
public function offsetGet($offset) |
38
|
|
|
{ |
39
|
|
|
return isset($this->array[$offset]) ? $this->array[$offset] : null; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Offset to set |
44
|
|
|
* @link http://php.net/manual/en/arrayaccess.offsetset.php |
45
|
|
|
* @param mixed $offset The offset to assign the value to. |
46
|
|
|
* @param mixed $value The value to set. |
47
|
|
|
*/ |
48
|
|
|
public function offsetSet($offset, $value) |
49
|
|
|
{ |
50
|
|
|
$this->array[$offset] = $value; |
|
|
|
|
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Whether a offset exists |
55
|
|
|
* @link http://php.net/manual/en/arrayaccess.offsetexists.php |
56
|
|
|
* |
57
|
|
|
* @param mixed $offset |
58
|
|
|
* @return bool |
59
|
|
|
*/ |
60
|
|
|
public function offsetExists($offset) |
61
|
|
|
{ |
62
|
|
|
return isset($this->array[$offset]); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Offset to unset |
67
|
|
|
* @link http://php.net/manual/en/arrayaccess.offsetunset.php |
68
|
|
|
* @param mixed $offset The offset to unset. |
69
|
|
|
*/ |
70
|
|
|
public function offsetUnset($offset) |
71
|
|
|
{ |
72
|
|
|
unset($this->array[$offset]); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* {@inheritDoc} |
77
|
|
|
*/ |
78
|
|
|
public function count() |
79
|
|
|
{ |
80
|
|
|
return count($this->array); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|