File tree Expand file tree Collapse file tree 2 files changed +37
-1
lines changed
src/GetStream/StreamLaravel Expand file tree Collapse file tree 2 files changed +37
-1
lines changed Original file line number Diff line number Diff line change 11<?php namespace GetStream \StreamLaravel ;
22
3- class EnrichedActivity implements \ArrayAccess {
3+ class EnrichedActivity implements \ArrayAccess, \Iterator {
44 private $ activityData = array ();
55 private $ notEnrichedData = array ();
66
@@ -49,4 +49,30 @@ public function offsetGet($offset)
4949 return isset ($ this ->activityData [$ offset ]) ? $ this ->activityData [$ offset ] : null ;
5050 }
5151
52+ // Array iteration methods
53+ public function rewind ()
54+ {
55+ reset ($ this ->activityData );
56+ }
57+
58+ public function current ()
59+ {
60+ return current ($ this ->activityData );
61+ }
62+
63+ public function key ()
64+ {
65+ return key ($ this ->activityData );
66+ }
67+
68+ public function next ()
69+ {
70+ return next ($ this ->activityData );
71+ }
72+
73+ public function valid ()
74+ {
75+ return (bool ) $ this ->current ();
76+ }
77+
5278}
Original file line number Diff line number Diff line change @@ -30,4 +30,14 @@ public function testTrackNotEnrichedField()
3030 $ this ->assertSame ($ activity ->getNotEnrichedData (), array ('missing ' => 'value ' ));
3131 }
3232
33+ public function testIterable ()
34+ {
35+ $ activity = new EnrichedActivity (array ('1 ' =>1 , '2 ' => 3 ));
36+ $ sum = 0 ;
37+ foreach ($ activity as $ field => $ value ) {
38+ $ sum += $ value ;
39+ }
40+ $ this ->assertSame ($ sum , 4 );
41+ }
42+
3343}
You can’t perform that action at this time.
0 commit comments