1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace GetStream\Doctrine; |
4
|
|
|
|
5
|
|
|
use ArrayAccess; |
6
|
|
|
use ArrayIterator; |
7
|
|
|
use IteratorAggregate; |
8
|
|
|
use Traversable; |
9
|
|
|
|
10
|
|
|
class EnrichedActivity implements ArrayAccess, IteratorAggregate |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @var array |
14
|
|
|
*/ |
15
|
|
|
private $activityData = []; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var array |
19
|
|
|
*/ |
20
|
|
|
private $notEnrichedData = []; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @param array $activityData |
24
|
|
|
*/ |
25
|
8 |
|
public function __construct(array $activityData) |
26
|
|
|
{ |
27
|
8 |
|
$this->activityData = $activityData; |
28
|
8 |
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @param string $field |
32
|
|
|
* @param mixed $value |
33
|
|
|
*/ |
34
|
2 |
|
public function trackNotEnrichedField($field, $value) |
35
|
|
|
{ |
36
|
2 |
|
$this->notEnrichedData[$field] = $value; |
37
|
2 |
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @return array |
41
|
|
|
*/ |
42
|
2 |
|
public function getNotEnrichedData() |
43
|
|
|
{ |
44
|
2 |
|
return $this->notEnrichedData; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @return bool |
49
|
|
|
*/ |
50
|
2 |
|
public function enriched() |
51
|
|
|
{ |
52
|
2 |
|
return empty($this->notEnrichedData); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
// ArrayAccess implementation methods |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @param mixed $offset |
59
|
|
|
* @param mixed $value |
60
|
|
|
*/ |
61
|
2 |
|
public function offsetSet($offset, $value) |
62
|
|
|
{ |
63
|
2 |
|
if (is_null($offset)) { |
64
|
1 |
|
$this->activityData[] = $value; |
65
|
|
|
} else { |
66
|
2 |
|
$this->activityData[$offset] = $value; |
67
|
|
|
} |
68
|
2 |
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @param mixed $offset |
72
|
|
|
* |
73
|
|
|
* @return bool |
74
|
|
|
*/ |
75
|
5 |
|
public function offsetExists($offset) |
76
|
|
|
{ |
77
|
5 |
|
return isset($this->activityData[$offset]); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @param mixed $offset |
82
|
|
|
*/ |
83
|
1 |
|
public function offsetUnset($offset) |
84
|
|
|
{ |
85
|
1 |
|
unset($this->activityData[$offset]); |
86
|
1 |
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @param mixed $offset |
90
|
|
|
* |
91
|
|
|
* @return mixed|null |
92
|
|
|
*/ |
93
|
4 |
|
public function offsetGet($offset) |
94
|
|
|
{ |
95
|
4 |
|
return isset($this->activityData[$offset]) ? $this->activityData[$offset] : null; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Retrieve an external iterator |
100
|
|
|
* |
101
|
|
|
* @return Traversable |
102
|
|
|
*/ |
103
|
7 |
|
public function getIterator() |
104
|
|
|
{ |
105
|
7 |
|
return new ArrayIterator($this->activityData); |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|