22
33namespace Sevavietl \Arrays ;
44
5- class CompositeKeyArray implements \ArrayAccess
5+ class CompositeKeyArray extends BaseArray
66{
7- protected $ array ;
7+ protected $ container ;
88 protected $ undefinedOffsetAction ;
99
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-
3010 public function toArray ()
3111 {
32- return $ this ->array ;
12+ return $ this ->container ;
3313 }
3414
3515 protected $ offsets ;
@@ -39,7 +19,7 @@ public function offsetExists($offset)
3919 $ this ->setOffsets ($ offset );
4020
4121 return $ this ->walkThroughOffsets (
42- $ this ->array ,
22+ $ this ->container ,
4323 function ($ array , $ offset ) {
4424 return isset ($ array [$ offset ]);
4525 },
@@ -54,7 +34,7 @@ public function offsetGet($offset)
5434 $ this ->setOffsets ($ offset );
5535
5636 return $ this ->walkThroughOffsets (
57- $ this ->array ,
37+ $ this ->container ,
5838 function ($ array , $ offset ) {
5939 return $ array [$ offset ];
6040 },
@@ -96,7 +76,7 @@ public function offsetSet($offset, $value)
9676 };
9777
9878 return $ this ->walkThroughOffsets (
99- $ this ->array ,
79+ $ this ->container ,
10080 $ baseCaseAction ,
10181 $ offsetNotExistsAction
10282 );
@@ -107,7 +87,7 @@ public function offsetUnset($offset)
10787 $ this ->setOffsets ($ offset );
10888
10989 return $ this ->walkThroughOffsets (
110- $ this ->array ,
90+ $ this ->container ,
11191 function (&$ array , $ offset ) {
11292 unset($ array [$ offset ]);
11393 },
0 commit comments