blob: 3ac477426c418548595f147fb8411fddae4862b2 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
+++
title = "Workflow"
name = "workflow"
repository = "https://git.neonxp.ru/workflow.git"
description = "Простой конечный автомат для Go"
gomod = true
outputs = ["html"]
+++
Простой конечный автомат, похожий на [Symfony Workflow](https://github.com/symfony/workflow).
## Пример
```go
o := new(ObjectImplementedPlaceer)
w := NewWorkflow("Start")
w.AddTransition("Start", "A")
w.AddTransition("Start", "B")
w.AddTransition("A", "C")
w.AddTransition("B", "D")
w.AddTransition( "C", "D")
w.AddTransition("C", "Finish")
w.AddTransition("D", "Finish")
w.Can(o, "A") // == nil
w.Can(o, "C") // == ErrTransitionNotFound
w.GetEnabledTransitions(o) // []Place{"A", "B"}
w.Apply(o, "A") // o now at "A" place
w.GetEnabledTransitions(o) // []Place{"C"}
w.DumpToDot() // See above
```
## Дамп в формат dot
```
digraph {
Start[color="blue"]
Start -> A[label="Start → A"];
Start -> B[label="Start → B"];
A -> C[label="A → C"];
B -> D[label="B → D"];
C -> D[label="C → D"];
C -> Finish[label="C → Finish"];
D -> Finish[label="D → Finish"];
}
```
{{< graph >}}
flowchart TD
Start -->|Start → A| A
Start -->|Start → B| B
A -->|A → C| C
B -->|B → D| D
C -->|C → D| D
C -->|C → Finish| Finish
D -->|D → Finish| Finish
{{< /graph >}}
|