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