1 | <?php |
||
27 | class Transition extends Base |
||
28 | { |
||
29 | /** |
||
30 | * Actions which will be executed during the transition. |
||
31 | * |
||
32 | * @var Action[] |
||
33 | */ |
||
34 | private $actions = []; |
||
35 | |||
36 | /** |
||
37 | * Post actions which will be executed when new step is reached. |
||
38 | * |
||
39 | * @var Action[] |
||
40 | */ |
||
41 | private $postActions = []; |
||
42 | |||
43 | /** |
||
44 | * The step the transition is moving to. |
||
45 | * |
||
46 | * @var Step |
||
47 | */ |
||
48 | private $stepTo; |
||
49 | |||
50 | /** |
||
51 | * A pre condition which has to be passed to execute transition. |
||
52 | * |
||
53 | * @var AndCondition |
||
54 | */ |
||
55 | private $preCondition; |
||
56 | |||
57 | /** |
||
58 | * A condition which has to be passed to execute the transition. |
||
59 | * |
||
60 | * @var AndCondition |
||
61 | */ |
||
62 | private $condition; |
||
63 | |||
64 | /** |
||
65 | * A set of permission being assigned to the transition. |
||
66 | * |
||
67 | * @var Permission|null |
||
68 | */ |
||
69 | private $permission; |
||
70 | |||
71 | /** |
||
72 | * The corresponding workflow. |
||
73 | * |
||
74 | * @var Workflow |
||
75 | */ |
||
76 | private $workflow; |
||
77 | |||
78 | /** |
||
79 | * Transition constructor. |
||
80 | * |
||
81 | * @param string $name Name of the element. |
||
82 | * @param Workflow $workflow The workflow to which the transition belongs. |
||
83 | * @param Step $stepTo The target step. |
||
84 | * @param string $label Label of the element. |
||
85 | * @param array $config Configuration values. |
||
86 | */ |
||
87 | public function __construct(string $name, Workflow $workflow, Step $stepTo, string $label = '', array $config = []) |
||
96 | |||
97 | /** |
||
98 | * Get the workflow. |
||
99 | * |
||
100 | * @return Workflow |
||
101 | */ |
||
102 | public function getWorkflow(): Workflow |
||
106 | |||
107 | /** |
||
108 | * Add an action to the transition. |
||
109 | * |
||
110 | * @param Action $action The added action. |
||
111 | * |
||
112 | * @return $this |
||
113 | */ |
||
114 | public function addAction(Action $action): self |
||
120 | |||
121 | /** |
||
122 | * Get all actions. |
||
123 | * |
||
124 | * @return Action[]|iterable |
||
125 | */ |
||
126 | public function getActions(): iterable |
||
130 | |||
131 | /** |
||
132 | * Add an post action to the transition. |
||
133 | * |
||
134 | * @param Action $action The added action. |
||
135 | * |
||
136 | * @return $this |
||
137 | */ |
||
138 | public function addPostAction(Action $action): self |
||
144 | |||
145 | /** |
||
146 | * Get all post actions. |
||
147 | * |
||
148 | * @return Action[]|iterable |
||
149 | */ |
||
150 | public function getPostActions(): iterable |
||
154 | |||
155 | /** |
||
156 | * Get the target step. |
||
157 | * |
||
158 | * @return Step |
||
159 | */ |
||
160 | public function getStepTo():? Step |
||
164 | |||
165 | /** |
||
166 | * Get the condition. |
||
167 | * |
||
168 | * @return Condition|null |
||
169 | */ |
||
170 | public function getCondition():? Condition |
||
174 | |||
175 | /** |
||
176 | * Add a condition. |
||
177 | * |
||
178 | * @param Condition $condition The new condition. |
||
179 | * |
||
180 | * @return $this |
||
181 | */ |
||
182 | public function addCondition(Condition $condition): self |
||
191 | |||
192 | /** |
||
193 | * Get the precondition. |
||
194 | * |
||
195 | * @return Condition |
||
196 | */ |
||
197 | public function getPreCondition():? Condition |
||
201 | |||
202 | /** |
||
203 | * Add a precondition precondition. |
||
204 | * |
||
205 | * @param Condition $preCondition The new precondition. |
||
206 | * |
||
207 | * @return $this |
||
208 | */ |
||
209 | public function addPreCondition(Condition $preCondition): self |
||
219 | |||
220 | /** |
||
221 | * Consider if user input is required. |
||
222 | * |
||
223 | * @param Item $item Workflow item. |
||
224 | * |
||
225 | * @return array |
||
226 | */ |
||
227 | public function getRequiredPayloadProperties(Item $item): array |
||
242 | |||
243 | /** |
||
244 | * Validate the given item and context (payload properties). |
||
245 | * |
||
246 | * @param Item $item Workflow item. |
||
247 | * @param Context $context Transition context. |
||
248 | * |
||
249 | * @return bool |
||
250 | */ |
||
251 | public function validate(Item $item, Context $context): bool |
||
261 | |||
262 | /** |
||
263 | * Consider if transition is allowed. |
||
264 | * |
||
265 | * @param Item $item The Item. |
||
266 | * @param Context $context The transition context. |
||
267 | * |
||
268 | * @return bool |
||
269 | */ |
||
270 | public function isAllowed(Item $item, Context $context): bool |
||
278 | |||
279 | /** |
||
280 | * Consider if transition is available. |
||
281 | * |
||
282 | * If a transition can be available but it is not allowed depending on the user input. |
||
283 | * |
||
284 | * @param Item $item The Item. |
||
285 | * @param Context $context The transition context. |
||
286 | * |
||
287 | * @return bool |
||
288 | */ |
||
289 | public function isAvailable(Item $item, Context $context): bool |
||
297 | |||
298 | /** |
||
299 | * Check the precondition. |
||
300 | * |
||
301 | * @param Item $item The Item. |
||
302 | * @param Context $context The transition context. |
||
303 | * |
||
304 | * @return bool |
||
305 | */ |
||
306 | public function checkPreCondition(Item $item, Context $context): bool |
||
310 | |||
311 | /** |
||
312 | * Check the condition. |
||
313 | * |
||
314 | * @param Item $item The Item. |
||
315 | * @param Context $context The transition context. |
||
316 | * |
||
317 | * @return bool |
||
318 | */ |
||
319 | public function checkCondition(Item $item, Context $context): bool |
||
323 | |||
324 | /** |
||
325 | * Set a permission to the transition. |
||
326 | * |
||
327 | * @param Permission $permission Permission being assigned. |
||
328 | * |
||
329 | * @return $this |
||
330 | */ |
||
331 | public function setPermission(Permission $permission): self |
||
337 | |||
338 | /** |
||
339 | * Consider if permission is assigned to transition. |
||
340 | * |
||
341 | * @param Permission $permission Permission being check. |
||
342 | * |
||
343 | * @return bool |
||
344 | */ |
||
345 | public function hasPermission(Permission $permission): bool |
||
353 | |||
354 | /** |
||
355 | * Get assigned permission. Returns null if no transition is set. |
||
356 | * |
||
357 | * @return Permission|null |
||
358 | */ |
||
359 | public function getPermission():? Permission |
||
363 | |||
364 | /** |
||
365 | * Execute all actions. |
||
366 | * |
||
367 | * @param Item $item The workflow item. |
||
368 | * @param Context $context The transition context. |
||
369 | * |
||
370 | * @return bool |
||
371 | */ |
||
372 | public function executeActions(Item $item, Context $context): bool |
||
376 | |||
377 | /** |
||
378 | * Execute all actions. |
||
379 | * |
||
380 | * @param Item $item The workflow item. |
||
381 | * @param Context $context The transition context. |
||
382 | * |
||
383 | * @return bool |
||
384 | */ |
||
385 | public function executePostActions(Item $item, Context $context): bool |
||
389 | |||
390 | /** |
||
391 | * Perform condition check. |
||
392 | * |
||
393 | * @param Condition|null $condition Condition to be checked. |
||
394 | * @param Item $item Workflow item. |
||
395 | * @param Context $context Condition context. |
||
396 | * |
||
397 | * @return bool |
||
398 | */ |
||
399 | private function performConditionCheck($condition, $item, $context): bool |
||
407 | |||
408 | /** |
||
409 | * Execute the actions. |
||
410 | * |
||
411 | * @param Item $item Workflow item. |
||
412 | * @param Context $context Condition context. |
||
413 | * @param Action[] $actions Action to execute. |
||
414 | * |
||
415 | * @return bool |
||
416 | */ |
||
417 | private function doExecuteActions(Item $item, Context $context, $actions): bool |
||
436 | } |
||
437 |