1 | <?php |
||
30 | class Transition extends Base |
||
31 | { |
||
32 | /** |
||
33 | * Actions which will be executed during the transition. |
||
34 | * |
||
35 | * @var Action[] |
||
36 | */ |
||
37 | private $actions = array(); |
||
38 | |||
39 | /** |
||
40 | * Post actions which will be executed when new step is reached. |
||
41 | * |
||
42 | * @var Action[] |
||
43 | */ |
||
44 | private $postActions = array(); |
||
45 | |||
46 | /** |
||
47 | * The step the transition is moving to. |
||
48 | * |
||
49 | * @var Step |
||
50 | */ |
||
51 | private $stepTo; |
||
52 | |||
53 | /** |
||
54 | * A pre condition which has to be passed to execute transition. |
||
55 | * |
||
56 | * @var AndCondition |
||
57 | */ |
||
58 | private $preCondition; |
||
59 | |||
60 | /** |
||
61 | * A condition which has to be passed to execute the transition. |
||
62 | * |
||
63 | * @var AndCondition |
||
64 | */ |
||
65 | private $condition; |
||
66 | |||
67 | /** |
||
68 | * A set of permission being assigned to the transition. |
||
69 | * |
||
70 | * @var Permission|null |
||
71 | */ |
||
72 | private $permission; |
||
73 | |||
74 | /** |
||
75 | * The corresponding workflow. |
||
76 | * |
||
77 | * @var Workflow |
||
78 | */ |
||
79 | private $workflow; |
||
80 | |||
81 | /** |
||
82 | * Transition constructor. |
||
83 | * |
||
84 | * @param string $name Name of the element. |
||
85 | * @param Workflow $workflow The workflow to which the transition belongs. |
||
86 | * @param Step $stepTo The target step. |
||
87 | * @param string $label Label of the element. |
||
88 | * @param array $config Configuration values. |
||
89 | */ |
||
90 | public function __construct($name, Workflow $workflow, Step $stepTo, $label = null, array $config = []) |
||
99 | |||
100 | /** |
||
101 | * Get the workflow. |
||
102 | * |
||
103 | * @return Workflow |
||
104 | */ |
||
105 | public function getWorkflow(): Workflow |
||
109 | |||
110 | /** |
||
111 | * Add an action to the transition. |
||
112 | * |
||
113 | * @param Action $action The added action. |
||
114 | * |
||
115 | * @return $this |
||
116 | */ |
||
117 | public function addAction(Action $action): self |
||
123 | |||
124 | /** |
||
125 | * Get all actions. |
||
126 | * |
||
127 | * @return Action[]|iterable |
||
128 | */ |
||
129 | public function getActions(): iterable |
||
133 | |||
134 | /** |
||
135 | * Add an post action to the transition. |
||
136 | * |
||
137 | * @param Action $action The added action. |
||
138 | * |
||
139 | * @return $this |
||
140 | */ |
||
141 | public function addPostAction(Action $action): self |
||
147 | |||
148 | /** |
||
149 | * Get all post actions. |
||
150 | * |
||
151 | * @return Action[]|iterable |
||
152 | */ |
||
153 | public function getPostActions(): iterable |
||
157 | |||
158 | /** |
||
159 | * Get the target step. |
||
160 | * |
||
161 | * @return Step |
||
162 | */ |
||
163 | public function getStepTo():? Step |
||
167 | |||
168 | /** |
||
169 | * Get the condition. |
||
170 | * |
||
171 | * @return Condition|null |
||
172 | */ |
||
173 | public function getCondition():? Condition |
||
177 | |||
178 | /** |
||
179 | * Add a condition. |
||
180 | * |
||
181 | * @param Condition $condition The new condition. |
||
182 | * |
||
183 | * @return $this |
||
184 | */ |
||
185 | public function addCondition(Condition $condition) |
||
194 | |||
195 | /** |
||
196 | * Get the precondition. |
||
197 | * |
||
198 | * @return Condition |
||
199 | */ |
||
200 | public function getPreCondition():? Condition |
||
204 | |||
205 | /** |
||
206 | * Add a precondition precondition. |
||
207 | * |
||
208 | * @param Condition $preCondition The new precondition. |
||
209 | * |
||
210 | * @return $this |
||
211 | */ |
||
212 | public function addPreCondition(Condition $preCondition): self |
||
222 | |||
223 | /** |
||
224 | * Consider if user input is required. |
||
225 | * |
||
226 | * @param Item $item Workflow item. |
||
227 | * |
||
228 | * @return array |
||
229 | */ |
||
230 | public function getRequiredPayloadProperties(Item $item): array |
||
241 | |||
242 | /** |
||
243 | * Consider if transition is allowed. |
||
244 | * |
||
245 | * @param Item $item The Item. |
||
246 | * @param Context $context The transition context. |
||
247 | * @param ErrorCollection $errorCollection The error collection. |
||
248 | * |
||
249 | * @return bool |
||
250 | */ |
||
251 | public function isAllowed(Item $item, Context $context, ErrorCollection $errorCollection): bool |
||
259 | |||
260 | /** |
||
261 | * Consider if transition is available. |
||
262 | * |
||
263 | * If a transition can be available but it is not allowed depending on the user input. |
||
264 | * |
||
265 | * @param Item $item The Item. |
||
266 | * @param Context $context The transition context. |
||
267 | * @param ErrorCollection $errorCollection The error collection. |
||
268 | * |
||
269 | * @return bool |
||
270 | */ |
||
271 | public function isAvailable(Item $item, Context $context, ErrorCollection $errorCollection): bool |
||
279 | |||
280 | /** |
||
281 | * Check the precondition. |
||
282 | * |
||
283 | * @param Item $item The Item. |
||
284 | * @param Context $context The transition context. |
||
285 | * @param ErrorCollection $errorCollection The error collection. |
||
286 | * |
||
287 | * @return bool |
||
288 | */ |
||
289 | public function checkPreCondition(Item $item, Context $context, ErrorCollection $errorCollection) |
||
293 | |||
294 | /** |
||
295 | * Check the condition. |
||
296 | * |
||
297 | * @param Item $item The Item. |
||
298 | * @param Context $context The transition context. |
||
299 | * @param ErrorCollection $errorCollection The error collection. |
||
300 | * |
||
301 | * @return bool |
||
302 | */ |
||
303 | public function checkCondition(Item $item, Context $context, ErrorCollection $errorCollection) |
||
307 | |||
308 | /** |
||
309 | * Set a permission to the transition. |
||
310 | * |
||
311 | * @param Permission $permission Permission being assigned. |
||
312 | * |
||
313 | * @return $this |
||
314 | */ |
||
315 | public function setPermission(Permission $permission) |
||
321 | |||
322 | /** |
||
323 | * Consider if permission is assigned to transition. |
||
324 | * |
||
325 | * @param Permission $permission Permission being check. |
||
326 | * |
||
327 | * @return bool |
||
328 | */ |
||
329 | public function hasPermission(Permission $permission) |
||
337 | |||
338 | /** |
||
339 | * Get assigned permission. Returns null if no transition is set. |
||
340 | * |
||
341 | * @return Permission|null |
||
342 | */ |
||
343 | public function getPermission() |
||
347 | |||
348 | /** |
||
349 | * Execute all actions. |
||
350 | * |
||
351 | * @param Item $item The workflow item. |
||
352 | * @param Context $context The transition context. |
||
353 | * @param ErrorCollection $errorCollection The error collection. |
||
354 | * |
||
355 | * @return bool |
||
356 | */ |
||
357 | public function executeActions(Item $item, Context $context, ErrorCollection $errorCollection) |
||
361 | |||
362 | /** |
||
363 | * Execute all actions. |
||
364 | * |
||
365 | * @param Item $item The workflow item. |
||
366 | * @param Context $context The transition context. |
||
367 | * @param ErrorCollection $errorCollection The error collection. |
||
368 | * |
||
369 | * @return bool |
||
370 | */ |
||
371 | public function executePostActions(Item $item, Context $context, ErrorCollection $errorCollection) |
||
375 | |||
376 | /** |
||
377 | * Perform condition check. |
||
378 | * |
||
379 | * @param Condition|null $condition Condition to be checked. |
||
380 | * @param Item $item Workflow item. |
||
381 | * @param Context $context Condition context. |
||
382 | * @param ErrorCollection $errorCollection Error collection. |
||
383 | * |
||
384 | * @return bool |
||
385 | */ |
||
386 | private function performConditionCheck($condition, $item, $context, ErrorCollection $errorCollection) |
||
394 | |||
395 | /** |
||
396 | * Execute the actions. |
||
397 | * |
||
398 | * @param Item $item Workflow item. |
||
399 | * @param Context $context Condition context. |
||
400 | * @param ErrorCollection $errorCollection Error collection. |
||
401 | * @param Action[] $actions Action to execute. |
||
402 | * |
||
403 | * @return bool |
||
404 | */ |
||
405 | private function doExecuteActions(Item $item, Context $context, ErrorCollection $errorCollection, $actions) |
||
424 | } |
||
425 |