17
17
use Symfony \Component \Console \Input \InputOption ;
18
18
use Symfony \Component \Console \Output \OutputInterface ;
19
19
use Symfony \Component \Workflow \Dumper \GraphvizDumper ;
20
+ use Symfony \Component \Workflow \Dumper \PlantUmlDumper ;
20
21
use Symfony \Component \Workflow \Dumper \StateMachineGraphvizDumper ;
21
22
use Symfony \Component \Workflow \Marking ;
22
23
@@ -39,13 +40,15 @@ protected function configure()
39
40
new InputArgument ('name ' , InputArgument::REQUIRED , 'A workflow name ' ),
40
41
new InputArgument ('marking ' , InputArgument::IS_ARRAY , 'A marking (a list of places) ' ),
41
42
new InputOption ('label ' , 'l ' , InputArgument::OPTIONAL , 'Labels a graph ' ),
43
+ new InputOption ('dump-format ' , null , InputOption::VALUE_REQUIRED , 'The dump format [dot|puml] ' , 'dot ' ),
42
44
))
43
45
->setDescription ('Dump a workflow ' )
44
46
->setHelp (<<<'EOF'
45
47
The <info>%command.name%</info> command dumps the graphical representation of a
46
- workflow in DOT format
48
+ workflow in different formats
47
49
48
- %command.full_name% <workflow name> | dot -Tpng > workflow.png
50
+ <info>DOT</info>: %command.full_name% <workflow name> | dot -Tpng > workflow.png
51
+ <info>PUML</info>: %command.full_name% <workflow name> --dump-format=puml | java -jar plantuml.jar -p > workflow.png
49
52
50
53
EOF
51
54
)
@@ -59,16 +62,27 @@ protected function execute(InputInterface $input, OutputInterface $output)
59
62
{
60
63
$ container = $ this ->getApplication ()->getKernel ()->getContainer ();
61
64
$ serviceId = $ input ->getArgument ('name ' );
65
+
62
66
if ($ container ->has ('workflow. ' .$ serviceId )) {
63
67
$ workflow = $ container ->get ('workflow. ' .$ serviceId );
64
- $ dumper = new GraphvizDumper () ;
68
+ $ type = ' workflow ' ;
65
69
} elseif ($ container ->has ('state_machine. ' .$ serviceId )) {
66
70
$ workflow = $ container ->get ('state_machine. ' .$ serviceId );
67
- $ dumper = new StateMachineGraphvizDumper () ;
71
+ $ type = ' state_machine ' ;
68
72
} else {
69
73
throw new \InvalidArgumentException (sprintf ('No service found for "workflow.%1$s" nor "state_machine.%1$s". ' , $ serviceId ));
70
74
}
71
75
76
+ if ('puml ' === $ input ->getOption ('dump-format ' )) {
77
+ $ dumper = new PlantUmlDumper (
78
+ 'workflow ' === $ type ? PlantUmlDumper::WORKFLOW_TRANSITION : PlantUmlDumper::STATEMACHINE_TRANSITION
79
+ );
80
+ } elseif ('workflow ' === $ type ) {
81
+ $ dumper = new GraphvizDumper ();
82
+ } else {
83
+ $ dumper = new StateMachineGraphvizDumper ();
84
+ }
85
+
72
86
$ marking = new Marking ();
73
87
74
88
foreach ($ input ->getArgument ('marking ' ) as $ place ) {
@@ -80,6 +94,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
80
94
if (null !== $ label && '' !== trim ($ label )) {
81
95
$ options = array ('graph ' => array ('label ' => $ label ));
82
96
}
97
+ $ options = array_replace ($ options , array ('name ' => $ serviceId , 'nofooter ' => true ));
83
98
$ output ->writeln ($ dumper ->dump ($ workflow ->getDefinition (), $ marking , $ options ));
84
99
}
85
100
}
0 commit comments