Skip to content

Commit 0df6b36

Browse files
committed
feature #24705 [Workflow] Add PlantUML dumper to workflow:dump command (Plopix)
This PR was merged into the 4.1-dev branch. Discussion ---------- [Workflow] Add PlantUML dumper to workflow:dump command | Q | A | ------------- | --- | Branch | 4.1 | Bug fix | no | New feature | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | License | MIT | Doc PR | Will do depending on the comments about that PR Hello, `workflow:dump` exports workflows in `dot` format. To me, this format is not the easiest and not the simplest to use. Styles and logic are mixed together which makes it hard to read. [PlantUML](http://plantuml.com/) is a tool based on Graphviz like Dot but that generates nicer diagrams, more readable and most of all easier to adapt to your documentation. Just copy and paste the PUML on the website you will see the rendering live. Also, there is a [PHPStorm Plugin](https://plugins.jetbrains.com/plugin/7017-plantuml-integration) and [plenty of integration](http://plantuml.com/running) of this format. This PR adds 2 options * a `--dump-format=puml` option to the `workflow:dump` command to generate the workflows in PlantUML. * a `--puml-transition-format=square|arrow` option to the `workflow:dump` command to generate the workflows in PlantUML using a square shape or arrow for the transition. (see below) The conversion requires the PlantUML JAR, and can be used like that: ```bash php bin/console workflow:dump pull_request --dump-format=puml | java -jar plantuml.jar -p > workflow.png ``` > don't forget the `-p` to enable the "piping" Here is an example with `pull_request` workflow of the documentation (with no style and no marking): ``` @startuml title pull_request state start <<initial>> state coding state travis state review state merged state closed start --> travis: submit coding --> travis: update travis --> travis: update review --> travis: update travis --> review: wait_for_review review --> coding: request_change review --> merged: accept review --> closed: reject closed --> review: reopen @enduml ``` As PlantUML let us define styles, I have provided some by default that the user can override. Adding some marking: ```bash php bin/console workflow:dump pull_request travis review --dump-format=puml ``` will give us: ``` @startuml sprite $sf_logo [81x20/16z] { hPNRaYiX24K1xwBo_tyx6-qaCtDEJ-KXLYMTLbp0HWcHZr3KRDJ8z94HG3jZn4_mijbQ2ryJoFePtXLWA_qxyGy19DpdY_10z11ZAbGjFHRwcEbcKx5-wqsV yIMo8StMCHKh8ZUxnEwrZiwRAUOvy1lLcPQF4lEFAjhzMd5WOAqvKflS0Enx8PbihiSYXM8ClGVAseIWTAjCgVSAcnYbQG79xKFsZ0VnDCNc7AVBoPSMcTsX UnrujbYjjz0NnsObkTgnmolqJD4QgGUYTQiNe8eIjtx4b6Vv8nPGpncn3NJ8Geo9W9VW2wGACm_JzgIO8A8KXr2jUBCVGEAAJSZ6JUlsNnmOzmIYti9G7bjL 8InaHM9G40NkwTG7OxrggvNIejA8AZuqyWjOzTIKi-wwYvjeHYesSWuPiTGDN5THzkYLU4MD5r2_0PDhG7LIUG33z5HtM6CP3icyWEVOS61sD_2ZsBfJdbVA qM53XHDUwhY0TAwPug3OG9NonRFhO8ynF3I4unuAMDHmSrXH57V1RGvl9jafuZF9ZhqjWOEh98y0tUYGsUxkBSllIyBdT2oM5Fn2-ut-fzsq_cQNuL6Uvwqr knh4RrvOKzxZfLV3s0rs_R_1SdYt3VxeQ1_y2_W2 } title pull_request skinparam titleBorderRoundCorner 15 skinparam titleBorderThickness 2 skinparam state { BackgroundColor<<initial>> #87b741 BackgroundColor<<marked>> #3887C6 BorderColor #3887C6 BorderColor<<marked>> Black FontColor<<marked>> White } state start <<initial>> state coding state travis <<marked>> state review <<marked>> state merged state closed start --> travis: submit coding --> travis: update travis --> travis: update review --> travis: update travis --> review: wait_for_review review --> coding: request_change review --> merged: accept review --> closed: reject closed --> review: reopen footer \nGenerated by <$sf_logo> **Workflow Component** and **PlantUML** @enduml ``` Which gives you that: ![workflow](https://user-images.githubusercontent.com/313532/32086584-253e39c0-ba8b-11e7-82c7-fa24309dbcd6.png) With `square` as transition, it gives you that: ![workflow](https://user-images.githubusercontent.com/313532/32533123-a8ea4530-c403-11e7-8f88-4f18d5e23a28.png) Hope you will find that interesting! Commits ------- 1497d36cab Add option to the workflow:dump command to allow PlantUML format dump
2 parents 867794d + c7a1f90 commit 0df6b36

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)