1 | <?php |
||
22 | final class ProjectorState implements JsonSerializable |
||
23 | { |
||
24 | |||
25 | /** |
||
26 | * @var string |
||
27 | */ |
||
28 | private $name; |
||
29 | |||
30 | /** |
||
31 | * @var EventId |
||
32 | */ |
||
33 | private $lastEvent; |
||
34 | |||
35 | /** |
||
36 | * @var bool |
||
37 | */ |
||
38 | private $halted = true; |
||
39 | |||
40 | /** |
||
41 | * @var bool |
||
42 | */ |
||
43 | private $projecting = false; |
||
44 | |||
45 | /** |
||
46 | * @var int |
||
47 | */ |
||
48 | private $projectorRunsFrom; |
||
49 | |||
50 | /** |
||
51 | * @var null|string |
||
52 | */ |
||
53 | private $reason = null; |
||
54 | |||
55 | /** |
||
56 | * Creates a Projector State record |
||
57 | * |
||
58 | * @param Projector $projector |
||
59 | */ |
||
60 | public function __construct(Projector $projector) |
||
65 | |||
66 | /** |
||
67 | * Projector name/identifier |
||
68 | * |
||
69 | * @return string |
||
70 | */ |
||
71 | public function name(): string |
||
75 | |||
76 | /** |
||
77 | * Last played event |
||
78 | * |
||
79 | * @return null|EventId |
||
80 | */ |
||
81 | public function lastEvent(): ?EventId |
||
85 | |||
86 | /** |
||
87 | * Registers last played event |
||
88 | * |
||
89 | * @param Event $event |
||
90 | */ |
||
91 | public function lastEventWas(Event $event): void |
||
97 | |||
98 | /** |
||
99 | * Projector halt state |
||
100 | * |
||
101 | * @return bool |
||
102 | */ |
||
103 | public function isHalted(): bool |
||
107 | |||
108 | /** |
||
109 | * Halts the projector |
||
110 | * |
||
111 | * @param string $reason The reason why projector should be halted |
||
112 | */ |
||
113 | public function halt(string $reason): void |
||
119 | |||
120 | /** |
||
121 | * Reports whether or not this projector is projecting an event stream |
||
122 | * |
||
123 | * @return bool |
||
124 | */ |
||
125 | public function isProjecting(): bool |
||
129 | |||
130 | /** |
||
131 | * Sets projecting state as started |
||
132 | */ |
||
133 | public function startProjecting(): void |
||
137 | |||
138 | /** |
||
139 | * Sets projecting state as stopped |
||
140 | */ |
||
141 | public function stopProjecting(): void |
||
145 | |||
146 | /** |
||
147 | * Projector run mode |
||
148 | * |
||
149 | * @return int |
||
150 | */ |
||
151 | public function projectorRunsFrom(): int |
||
155 | |||
156 | /** |
||
157 | * Reason why the projector was halted |
||
158 | * |
||
159 | * @return string|null |
||
160 | */ |
||
161 | public function whyIsHalted(): ?string |
||
165 | |||
166 | /** |
||
167 | * Specify data which should be serialized to JSON |
||
168 | * |
||
169 | * @return mixed data which can be serialized by json_encode(), |
||
170 | * which is a value of any type other than a resource. |
||
171 | */ |
||
172 | public function jsonSerialize() |
||
183 | } |
||
184 |