1 | <?php |
||
25 | class State |
||
26 | { |
||
27 | /** |
||
28 | * The state id. |
||
29 | * |
||
30 | * @var int |
||
31 | */ |
||
32 | private $stateId; |
||
33 | |||
34 | /** |
||
35 | * The entity id. |
||
36 | * |
||
37 | * @var EntityId |
||
38 | */ |
||
39 | private $entityId; |
||
40 | |||
41 | /** |
||
42 | * Store if transition was successful. |
||
43 | * |
||
44 | * @var bool |
||
45 | */ |
||
46 | private $successful; |
||
47 | |||
48 | /** |
||
49 | * The last transition. |
||
50 | * |
||
51 | * @var string |
||
52 | */ |
||
53 | private $transitionName; |
||
54 | |||
55 | /** |
||
56 | * The current step. |
||
57 | * |
||
58 | * @var string |
||
59 | */ |
||
60 | private $stepName; |
||
61 | |||
62 | /** |
||
63 | * Date being stored. |
||
64 | * |
||
65 | * @var array |
||
66 | */ |
||
67 | private $data = array(); |
||
68 | |||
69 | /** |
||
70 | * Date when state was reached. |
||
71 | * |
||
72 | * @var DateTimeImmutable |
||
73 | */ |
||
74 | private $reachedAt; |
||
75 | |||
76 | /** |
||
77 | * List of errors. |
||
78 | * |
||
79 | * @var array |
||
80 | */ |
||
81 | private $errors; |
||
82 | |||
83 | /** |
||
84 | * Name of the workflow. |
||
85 | * |
||
86 | * @var string |
||
87 | */ |
||
88 | private $workflowName; |
||
89 | |||
90 | /** |
||
91 | * Construct. |
||
92 | * |
||
93 | * @param EntityId $entityId The entity id. |
||
94 | * @param string $workflowName Workflow name. |
||
95 | * @param string $transitionName The transition executed to reach the step. |
||
96 | * @param string $stepToName The step reached after transition. |
||
97 | * @param bool $successful Consider if transition was successful. |
||
98 | * @param array $data Stored data. |
||
99 | * @param DateTimeImmutable $reachedAt Time when state was reached. |
||
100 | * @param array $errors List of errors. |
||
101 | * @param int $stateId The state id of a persisted state. |
||
102 | * |
||
103 | * @SuppressWarnings(PHPMD.ExcessiveParameterList) |
||
104 | */ |
||
105 | public function __construct( |
||
126 | |||
127 | /** |
||
128 | * Create an initial state. |
||
129 | * |
||
130 | * @param EntityId $entityId The entity id. |
||
131 | * @param Transition $transition The current executed transition. |
||
132 | * @param Context $context The context. |
||
133 | * @param bool $success Success state. |
||
134 | * |
||
135 | * @return State |
||
136 | */ |
||
137 | public static function start( |
||
156 | |||
157 | /** |
||
158 | * Get step name. |
||
159 | * |
||
160 | * @return string |
||
161 | */ |
||
162 | public function getStepName(): string |
||
166 | |||
167 | /** |
||
168 | * Get transition name. |
||
169 | * |
||
170 | * @return string |
||
171 | */ |
||
172 | public function getTransitionName(): string |
||
176 | |||
177 | /** |
||
178 | * Get the workflow name. |
||
179 | * |
||
180 | * @return string |
||
181 | */ |
||
182 | public function getWorkflowName(): string |
||
186 | |||
187 | /** |
||
188 | * Get state data. |
||
189 | * |
||
190 | * @return array |
||
191 | */ |
||
192 | public function getData(): array |
||
196 | |||
197 | /** |
||
198 | * Get reached at time. |
||
199 | * |
||
200 | * @return DateTimeImmutable |
||
201 | */ |
||
202 | public function getReachedAt(): \DateTimeImmutable |
||
206 | |||
207 | /** |
||
208 | * Consider if state is successful. |
||
209 | * |
||
210 | * @return bool |
||
211 | */ |
||
212 | public function isSuccessful(): bool |
||
216 | |||
217 | /** |
||
218 | * Get the entity id. |
||
219 | * |
||
220 | * @return EntityId |
||
221 | */ |
||
222 | public function getEntityId(): EntityId |
||
226 | |||
227 | /** |
||
228 | * Get error messages. |
||
229 | * |
||
230 | * @return array |
||
231 | */ |
||
232 | public function getErrors(): array |
||
236 | |||
237 | /** |
||
238 | * Get state id. |
||
239 | * |
||
240 | * @return int|null |
||
241 | */ |
||
242 | public function getStateId():? int |
||
246 | |||
247 | /** |
||
248 | * Transit to a new state. |
||
249 | * |
||
250 | * @param Transition $transition The transition being performed. |
||
251 | * @param Context $context The transition context. |
||
252 | * @param bool $success The success state. |
||
253 | * |
||
254 | * @return State |
||
255 | */ |
||
256 | public function transit( |
||
275 | } |
||
276 |