1 | <?php |
||
22 | final class EventStream implements IteratorAggregate, Countable |
||
23 | { |
||
24 | /** |
||
25 | * @var Event[] |
||
26 | */ |
||
27 | private $events = []; |
||
28 | |||
29 | /** |
||
30 | * Creates an Event Stream |
||
31 | * |
||
32 | * @param array $events |
||
33 | * @throws \ReflectionException |
||
34 | */ |
||
35 | public function __construct(array $events = []) |
||
41 | |||
42 | /** |
||
43 | * Adds an event to the stream |
||
44 | * |
||
45 | * @param Event|StoredEvent $event |
||
46 | * |
||
47 | * @return EventStream |
||
48 | * @throws \ReflectionException |
||
49 | */ |
||
50 | public function add(Event $event): EventStream |
||
56 | |||
57 | /** |
||
58 | * Returns the event list as an array |
||
59 | * |
||
60 | * @return Event[] |
||
61 | */ |
||
62 | public function asArray(): array |
||
66 | |||
67 | /** |
||
68 | * Retrieve an external iterator |
||
69 | * |
||
70 | * @return ArrayIterator |
||
71 | */ |
||
72 | public function getIterator() |
||
76 | |||
77 | /** |
||
78 | * Count the events in this stream |
||
79 | * |
||
80 | * @return int |
||
81 | */ |
||
82 | public function count() |
||
86 | |||
87 | /** |
||
88 | * Returns true if this stream has no events |
||
89 | * |
||
90 | * @return bool |
||
91 | */ |
||
92 | public function isEmpty(): bool |
||
96 | |||
97 | /** |
||
98 | * Returns the first event in stream or null if stream is empty |
||
99 | * |
||
100 | * @return null|Event |
||
101 | */ |
||
102 | public function first(): ?Event |
||
106 | |||
107 | /** |
||
108 | * Returns the first event in stream or null if stream is empty |
||
109 | * |
||
110 | * @return null|Event |
||
111 | */ |
||
112 | public function last(): ?Event |
||
116 | } |
||
117 |