1 | <?php |
||
11 | class EventStreamFeedIterator implements \Iterator |
||
12 | { |
||
13 | /** |
||
14 | * @var StreamId |
||
15 | */ |
||
16 | private $streamId; |
||
17 | |||
18 | /** |
||
19 | * @var HttpClient |
||
20 | */ |
||
21 | private $client; |
||
22 | |||
23 | /** |
||
24 | * @var EventStreamFeed |
||
25 | */ |
||
26 | private $currentFeed; |
||
27 | |||
28 | /** |
||
29 | * @var string |
||
30 | */ |
||
31 | private $headUri; |
||
32 | |||
33 | /** |
||
34 | * @var string |
||
35 | */ |
||
36 | private $startUri; |
||
37 | |||
38 | /** |
||
39 | * @var ReadDirection |
||
40 | */ |
||
41 | private $readDirection; |
||
42 | |||
43 | /** |
||
44 | * @var bool |
||
45 | */ |
||
46 | private $initialized = false; |
||
47 | |||
48 | /** |
||
49 | * @var int |
||
50 | */ |
||
51 | private $currentKey = 0; |
||
52 | |||
53 | /** |
||
54 | * You can either iterate reading from the start of the stream, beginning at the first event registered and move forward, |
||
55 | * or you can iterate from the end, meaning that the first iteration will correspond to the latest event registered, |
||
56 | * and move backward to the beginning of the stream. |
||
57 | * |
||
58 | * @param StreamId $streamId |
||
59 | * @param HttpClient $client |
||
60 | * @param bool $readFromStart |
||
61 | */ |
||
62 | public function __construct(StreamId $streamId, HttpClient $client, $readFromStart = true) |
||
71 | |||
72 | /** |
||
73 | * @param string $uri |
||
74 | * |
||
75 | * @return EventStreamFeed |
||
76 | */ |
||
77 | private function readEventStreamFeed(string $uri): EventStreamFeed |
||
85 | |||
86 | /** |
||
87 | * @return EventStreamFeed |
||
88 | */ |
||
89 | public function current(): EventStreamFeed |
||
101 | |||
102 | public function next() |
||
110 | |||
111 | private function readForward() |
||
120 | |||
121 | private function readBackward() |
||
130 | |||
131 | /** |
||
132 | * @return int |
||
133 | */ |
||
134 | public function key(): int |
||
138 | |||
139 | /** |
||
140 | * @return bool |
||
141 | */ |
||
142 | public function valid(): bool |
||
146 | |||
147 | public function rewind() |
||
160 | |||
161 | /** |
||
162 | * @return string |
||
163 | */ |
||
164 | private function getStartUri(): string |
||
181 | |||
182 | /** |
||
183 | * @return ReadDirection |
||
184 | */ |
||
185 | public function getReadDirection() |
||
189 | } |
||
190 |