Skip to content

Commit 9333171

Browse files
committed
make EnrichedActivity iterable
1 parent 4a3b5c7 commit 9333171

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

src/GetStream/StreamLaravel/EnrichedActivity.php

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
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
}

tests/EnrichedActivityTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)