File tree Expand file tree Collapse file tree
typerocket/vendor/typerocket/core/src/Utility/Traits Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <?php
2+ namespace TypeRocket \Utility \Traits ;
3+
4+ trait ArrayAccessible
5+ {
6+ /**
7+ * @var array
8+ */
9+ protected array $ _items = [];
10+
11+ /**
12+ * @param int|string $offset
13+ * @param mixed $value
14+ * @return void
15+ */
16+ public function offsetSet ($ offset , $ value ) : void
17+ {
18+ $ location = $ this ->_location ?? '_items ' ;
19+
20+ if (is_null ($ offset )) {
21+ $ this ->{$ location }[] = $ value ;
22+ } else {
23+ $ this ->{$ location }[$ offset ] = $ value ;
24+ }
25+ }
26+
27+ /**
28+ * @param int|string $offset
29+ * @return bool
30+ */
31+ public function offsetExists ($ offset ) : bool
32+ {
33+ $ location = $ this ->_location ?? '_items ' ;
34+
35+ return isset ($ this ->{$ location }[$ offset ]);
36+ }
37+
38+ /**
39+ * @param int|string $offset
40+ * @return void
41+ */
42+ public function offsetUnset ($ offset ) : void
43+ {
44+ $ location = $ this ->_location ?? '_items ' ;
45+
46+ unset($ this ->{$ location }[$ offset ]);
47+ }
48+
49+ /**
50+ * @param int|string $offset
51+ * @return mixed|null
52+ */
53+ public function offsetGet ($ offset )
54+ {
55+ $ location = $ this ->_location ?? '_items ' ;
56+
57+ return $ this ->{$ location }[$ offset ] ?? null ;
58+ }
59+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace TypeRocket \Utility \Traits ;
4+
5+ trait ArrayIterable
6+ {
7+ /**
8+ * @var array
9+ */
10+ protected array $ _items = [];
11+
12+ function rewind ()
13+ {
14+ $ location = $ this ->_location ?? '_items ' ;
15+
16+ reset ($ this ->{$ location });
17+ }
18+
19+ function current ()
20+ {
21+ $ location = $ this ->_location ?? '_items ' ;
22+
23+ return current ($ this ->{$ location });
24+ }
25+
26+ function key ()
27+ {
28+ $ location = $ this ->_location ?? '_items ' ;
29+
30+ return key ($ this ->{$ location });
31+ }
32+
33+ function next ()
34+ {
35+ $ location = $ this ->_location ?? '_items ' ;
36+
37+ next ($ this ->{$ location });
38+ }
39+
40+ function valid ()
41+ {
42+ $ location = $ this ->_location ?? '_items ' ;
43+
44+ return key ($ this ->{$ location }) !== null ;
45+ }
46+ }
You can’t perform that action at this time.
0 commit comments