2
2
3
3
namespace Sevavietl \Arrays ;
4
4
5
- class CompositeKeyArray implements \ArrayAccess
5
+ class CompositeKeyArray extends BaseArray
6
6
{
7
- protected $ array ;
7
+ protected $ container ;
8
8
protected $ undefinedOffsetAction ;
9
9
10
- public function __construct (array $ array = [])
11
- {
12
- $ this ->array = $ array ;
13
-
14
- $ this ->undefinedOffsetAction = function ($ array , $ offset ) {
15
- $ offset = json_encode ($ offset );
16
-
17
- throw new UndefinedOffsetException (
18
- "Undefined offset $ offset. "
19
- );
20
- };
21
- }
22
-
23
- public function setUndefinedOffsetAction (Callable $ undefinedOffsetAction )
24
- {
25
- $ this ->undefinedOffsetAction = $ undefinedOffsetAction ;
26
-
27
- return $ this ;
28
- }
29
-
30
10
public function toArray ()
31
11
{
32
- return $ this ->array ;
12
+ return $ this ->container ;
33
13
}
34
14
35
15
protected $ offsets ;
@@ -39,7 +19,7 @@ public function offsetExists($offset)
39
19
$ this ->setOffsets ($ offset );
40
20
41
21
return $ this ->walkThroughOffsets (
42
- $ this ->array ,
22
+ $ this ->container ,
43
23
function ($ array , $ offset ) {
44
24
return isset ($ array [$ offset ]);
45
25
},
@@ -54,7 +34,7 @@ public function offsetGet($offset)
54
34
$ this ->setOffsets ($ offset );
55
35
56
36
return $ this ->walkThroughOffsets (
57
- $ this ->array ,
37
+ $ this ->container ,
58
38
function ($ array , $ offset ) {
59
39
return $ array [$ offset ];
60
40
},
@@ -96,7 +76,7 @@ public function offsetSet($offset, $value)
96
76
};
97
77
98
78
return $ this ->walkThroughOffsets (
99
- $ this ->array ,
79
+ $ this ->container ,
100
80
$ baseCaseAction ,
101
81
$ offsetNotExistsAction
102
82
);
@@ -107,7 +87,7 @@ public function offsetUnset($offset)
107
87
$ this ->setOffsets ($ offset );
108
88
109
89
return $ this ->walkThroughOffsets (
110
- $ this ->array ,
90
+ $ this ->container ,
111
91
function (&$ array , $ offset ) {
112
92
unset($ array [$ offset ]);
113
93
},
0 commit comments