1 | <?php |
||
28 | class Workflow extends Base |
||
29 | { |
||
30 | /** |
||
31 | * Transitions being available in the workflow. |
||
32 | * |
||
33 | * @var Transition[] |
||
34 | */ |
||
35 | private $transitions = array(); |
||
36 | |||
37 | /** |
||
38 | * Steps being available in the workflow. |
||
39 | * |
||
40 | * @var Step[] |
||
41 | */ |
||
42 | private $steps = array(); |
||
43 | |||
44 | /** |
||
45 | * The start transition. |
||
46 | * |
||
47 | * @var Transition |
||
48 | */ |
||
49 | private $startTransition; |
||
50 | |||
51 | /** |
||
52 | * Condition to supports if workflow can handle an entity. |
||
53 | * |
||
54 | * @var AndCondition |
||
55 | */ |
||
56 | private $condition; |
||
57 | |||
58 | /** |
||
59 | * Name of the provider. |
||
60 | * |
||
61 | * @var string |
||
62 | */ |
||
63 | private $providerName; |
||
64 | |||
65 | /** |
||
66 | * Construct. |
||
67 | * |
||
68 | * @param string $name The name of the workflow. |
||
69 | * @param string $providerName Name of the provider. |
||
70 | * @param string $label The label of the workflow. |
||
71 | * @param array $config Extra config. |
||
72 | */ |
||
73 | public function __construct(string $name, string $providerName, string $label = '', array $config = array()) |
||
79 | |||
80 | /** |
||
81 | * Add a transition to the workflow. |
||
82 | * |
||
83 | * @param Transition $transition Transition to be added. |
||
84 | * @param bool $startTransition True if transition will be the start transition. |
||
85 | * |
||
86 | * @return $this |
||
87 | */ |
||
88 | public function addTransition(Transition $transition, $startTransition = false): self |
||
102 | |||
103 | /** |
||
104 | * Get a transition by name. |
||
105 | * |
||
106 | * @param string $transitionName The name of the transition. |
||
107 | * |
||
108 | * @throws TransitionNotFound If transition is not found. |
||
109 | * |
||
110 | * @return \Netzmacht\Workflow\Flow\Transition If transition is not found. |
||
111 | */ |
||
112 | public function getTransition(string $transitionName): Transition |
||
122 | |||
123 | /** |
||
124 | * Get allowed transitions for a workflow item. |
||
125 | * |
||
126 | * @param Item $item Workflow item. |
||
127 | * @param Context $context Transition context. |
||
128 | * |
||
129 | * @throws StepNotFoundException If Step does not exists. |
||
130 | * @throws TransitionNotFound If transition does not exists. |
||
131 | * |
||
132 | * @return Transition[]|iterable |
||
133 | */ |
||
134 | public function getAvailableTransitions(Item $item, Context $context = null): iterable |
||
161 | |||
162 | /** |
||
163 | * Get all transitions. |
||
164 | * |
||
165 | * @return Transition[]|iterable |
||
166 | */ |
||
167 | public function getTransitions(): iterable |
||
171 | |||
172 | /** |
||
173 | * Check if transition is part of the workflow. |
||
174 | * |
||
175 | * @param string $transitionName Transition name. |
||
176 | * |
||
177 | * @return bool |
||
178 | */ |
||
179 | public function hasTransition(string $transitionName): bool |
||
189 | |||
190 | /** |
||
191 | * Check if a specific transition is available. |
||
192 | * |
||
193 | * @param Item $item The workflow item. |
||
194 | * @param Context $context Transition context. |
||
195 | * @param string $transitionName The transition name. |
||
196 | * |
||
197 | * @return bool |
||
198 | */ |
||
199 | public function isTransitionAvailable( |
||
217 | |||
218 | /** |
||
219 | * Add a new step to the workflow. |
||
220 | * |
||
221 | * @param Step $step Step to be added. |
||
222 | * |
||
223 | * @return $this |
||
224 | */ |
||
225 | public function addStep(Step $step): self |
||
231 | |||
232 | /** |
||
233 | * Get a step by step name. |
||
234 | * |
||
235 | * @param string $stepName The step name. |
||
236 | * |
||
237 | * @return Step |
||
238 | * |
||
239 | * @throws StepNotFoundException If step is not found. |
||
240 | */ |
||
241 | public function getStep(string $stepName): Step |
||
251 | |||
252 | /** |
||
253 | * Check if step with a name exist. |
||
254 | * |
||
255 | * @param string $stepName The step name. |
||
256 | * |
||
257 | * @return bool |
||
258 | */ |
||
259 | public function hasStep(string $stepName): bool |
||
269 | |||
270 | /** |
||
271 | * Set transition as start transition. |
||
272 | * |
||
273 | * @param string $transitionName Name of start transition. |
||
274 | * |
||
275 | * @throws TransitionNotFound If transition is not part of the workflow. |
||
276 | * |
||
277 | * @return $this |
||
278 | */ |
||
279 | public function setStartTransition(string $transitionName): self |
||
285 | |||
286 | /** |
||
287 | * Get the start transition. |
||
288 | * |
||
289 | * @return Transition |
||
290 | */ |
||
291 | public function getStartTransition(): Transition |
||
295 | |||
296 | /** |
||
297 | * Get the current condition. |
||
298 | * |
||
299 | * @return AndCondition |
||
300 | */ |
||
301 | public function getCondition():? AndCondition |
||
305 | |||
306 | /** |
||
307 | * Shortcut to add a condition to the condition collection. |
||
308 | * |
||
309 | * @param Condition $condition Condition to be added. |
||
310 | * |
||
311 | * @return $this |
||
312 | */ |
||
313 | public function addCondition(Condition $condition) |
||
323 | |||
324 | /** |
||
325 | * Get provider name. |
||
326 | * |
||
327 | * @return string |
||
328 | */ |
||
329 | public function getProviderName(): string |
||
333 | |||
334 | /** |
||
335 | * Consider if workflow is supports an entity. |
||
336 | * |
||
337 | * @param EntityId $entityId The entity id. |
||
338 | * @param mixed $entity The entity. |
||
339 | * |
||
340 | * @return bool |
||
341 | */ |
||
342 | public function supports(EntityId $entityId, $entity): bool |
||
350 | } |
||
351 |