Skip to content

Commit c7a1f90

Browse files
committed
Add option to the workflow:dump command to allow PlantUML format dump
1 parent df4781a commit c7a1f90

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

Command/WorkflowDumpCommand.php

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Symfony\Component\Console\Input\InputOption;
1818
use Symfony\Component\Console\Output\OutputInterface;
1919
use Symfony\Component\Workflow\Dumper\GraphvizDumper;
20+
use Symfony\Component\Workflow\Dumper\PlantUmlDumper;
2021
use Symfony\Component\Workflow\Dumper\StateMachineGraphvizDumper;
2122
use Symfony\Component\Workflow\Marking;
2223

@@ -39,13 +40,15 @@ protected function configure()
3940
new InputArgument('name', InputArgument::REQUIRED, 'A workflow name'),
4041
new InputArgument('marking', InputArgument::IS_ARRAY, 'A marking (a list of places)'),
4142
new InputOption('label', 'l', InputArgument::OPTIONAL, 'Labels a graph'),
43+
new InputOption('dump-format', null, InputOption::VALUE_REQUIRED, 'The dump format [dot|puml]', 'dot'),
4244
))
4345
->setDescription('Dump a workflow')
4446
->setHelp(<<<'EOF'
4547
The <info>%command.name%</info> command dumps the graphical representation of a
46-
workflow in DOT format
48+
workflow in different formats
4749
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
4952

5053
EOF
5154
)
@@ -59,16 +62,27 @@ protected function execute(InputInterface $input, OutputInterface $output)
5962
{
6063
$container = $this->getApplication()->getKernel()->getContainer();
6164
$serviceId = $input->getArgument('name');
65+
6266
if ($container->has('workflow.'.$serviceId)) {
6367
$workflow = $container->get('workflow.'.$serviceId);
64-
$dumper = new GraphvizDumper();
68+
$type = 'workflow';
6569
} elseif ($container->has('state_machine.'.$serviceId)) {
6670
$workflow = $container->get('state_machine.'.$serviceId);
67-
$dumper = new StateMachineGraphvizDumper();
71+
$type = 'state_machine';
6872
} else {
6973
throw new \InvalidArgumentException(sprintf('No service found for "workflow.%1$s" nor "state_machine.%1$s".', $serviceId));
7074
}
7175

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+
7286
$marking = new Marking();
7387

7488
foreach ($input->getArgument('marking') as $place) {
@@ -80,6 +94,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
8094
if (null !== $label && '' !== trim($label)) {
8195
$options = array('graph' => array('label' => $label));
8296
}
97+
$options = array_replace($options, array('name' => $serviceId, 'nofooter' => true));
8398
$output->writeln($dumper->dump($workflow->getDefinition(), $marking, $options));
8499
}
85100
}

0 commit comments

Comments
 (0)