如何导出工作流
为了帮助你调试工作流,你可以将它们生成为 SVG 或 PNG 图像的可视化表示。首先,安装以下任何用于生成图像的免费开源应用程序
- Graphviz,提供
dot
命令; - Mermaid CLI,提供
mmdc
命令; - PlantUML,提供
plantuml.jar
文件 (需要 Java)。
如果你在 Symfony 应用程序中定义工作流,请运行以下命令将其导出为图像
1 2 3 4 5 6 7 8 9 10 11 12 13 14
# using Graphviz's 'dot' and SVG images
$ php bin/console workflow:dump workflow-name | dot -Tsvg -o graph.svg
# using Graphviz's 'dot' and PNG images
$ php bin/console workflow:dump workflow-name | dot -Tpng -o graph.png
# using PlantUML's 'plantuml.jar'
$ php bin/console workflow:dump workflow_name --dump-format=puml | java -jar plantuml.jar -p > graph.png
# highlight 'place1' and 'place2' in the dumped workflow
$ php bin/console workflow:dump workflow-name place1 place2 | dot -Tsvg -o graph.svg
# using Mermaid.js CLI
$ php bin/console workflow:dump workflow_name --dump-format=mermaid | mmdc -o graph.svg
DOT 图像将如下所示

Mermaid 图像将如下所示

PlantUML 图像将如下所示

如果你在 Symfony 应用程序之外创建工作流,请使用 GraphvizDumper
或 StateMachineGraphvizDumper
类来创建 DOT 文件,并使用 PlantUmlDumper
来创建 PlantUML 文件
1 2 3 4 5 6 7
// Add this code to a PHP script; for example: dump-graph.php
$dumper = new GraphvizDumper();
echo $dumper->dump($definition);
# if you prefer PlantUML, use this code:
# $dumper = new PlantUmlDumper();
# echo $dumper->dump($definition);
1 2 3
# replace 'dump-graph.php' by the name of your PHP script
$ php dump-graph.php | dot -Tsvg -o graph.svg
$ php dump-graph.php | java -jar plantuml.jar -p > graph.png
样式
你可以在 workflow:dump
命令中使用 --with-metadata
选项来包含 place、transition 和工作流的元数据。
DOT 图像将如下所示

注意
--with-metadata
选项目前仅适用于 DOT dumper。
注意
label
元数据不包含在导出的元数据中,因为它用作 place 的标题。
你可以使用以下键的元数据来设置工作流的样式
对于 place
bg_color
:颜色;description
:描述状态的字符串。
对于 transition
label
:替换 transition 名称的字符串;color
:颜色;arrow_color
:颜色。
字符串可以包含 \n
字符以在多行中显示内容。颜色可以定义为
- 来自 PlantUML 颜色列表的颜色名称;
- 十六进制颜色(支持
#AABBCC
和#ABC
格式)。
注意
Mermaid dumper 不支持使用 arrow_color
为箭头头部着色,因为 Mermaid 不支持这样做。
以下是添加样式的拉取请求状态机的配置。
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
# config/packages/workflow.yaml
framework:
workflows:
pull_request:
type: 'state_machine'
marking_store:
type: 'method'
property: 'currentPlace'
supports:
- App\Entity\PullRequest
initial_marking: start
places:
start: ~
coding: ~
test: ~
review:
metadata:
description: Human review
merged: ~
closed:
metadata:
bg_color: DeepSkyBlue
transitions:
submit:
from: start
to: test
update:
from: [coding, test, review]
to: test
metadata:
arrow_color: Turquoise
wait_for_review:
from: test
to: review
metadata:
color: Orange
request_change:
from: review
to: coding
accept:
from: review
to: merged
metadata:
label: Accept PR
reject:
from: review
to: closed
reopen:
from: closed
to: review
PlantUML 图像将如下所示

本作品,包括代码示例,根据 Creative Commons BY-SA 3.0 许可协议获得许可。