-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Workflow] Add PlantUML dumper to workflow:dump command #24705
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
That is failing on Windows, but I don't really know why, probably a weird Windows specificity, or the END OF LINE? Thanks! |
@@ -1,6 +1,10 @@ | |||
CHANGELOG | |||
========= | |||
|
|||
3.5.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will be 4.1.0
not 3.5.0
(which never will be released)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
} | ||
|
||
return | ||
'@startuml'.PHP_EOL.static::SYMFONY_LOGO.PHP_EOL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be in previous line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
|
||
const MARKED = 'marked'; | ||
|
||
const SYMFONY_LOGO = 'sprite $sf_logo [81x20/16z] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better & probably safer than string comparison would be to save them as fixtures & compare results with pregenerated fixture.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure I understand here what you are proposing. Can you tell me more and I will be happy to change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I got it and I made changes accordingly.
@Nyholm or @lyrixx |
DST time, transient failure will be fixed tomorrow hopefully :) |
Oups Sorry I forgot to reply. Yes it's wanted. As a state machine can have many transition with the same name, the graph could be very ugly. that's why we did this. |
} else { | ||
throw new \InvalidArgumentException(sprintf('No service found for "workflow.%1$s" nor "state_machine.%1$s".', $serviceId)); | ||
} | ||
|
||
/** @var \Symfony\Component\Workflow\Workflow $workflow */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like it's useless
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not for PHPStorm ;) but I can remove it
@lyrixx I have added an option to let the user decide which transition he wants. |
Thanks. I will try your PR as soon as possible ;) |
@lyrixx time to review? :) |
|
||
public function __construct($transitionType) | ||
{ | ||
$this->transitionType = static::DEFAULT_TRANSITION_TYPE; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need to do this since it's already defaulted when you do $input->getOption('transition')
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree but this class could be used differently and without the command then I think it is correct to initialize it. no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not using
protected $transitionType = self::DEFAULT_TRANSITION_TYPE;
instead ?
I may be missing something but it feels better to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No that is me, I don't know I wanted to avoid that because of php versions but now for 4.x it is php 7 then we are all good to do that. And I think we were good before too...I was wrong. It is better now ;)
public function __construct($transitionType) | ||
{ | ||
$this->transitionType = static::DEFAULT_TRANSITION_TYPE; | ||
if ($transitionType == static::SQUARE_TRANSITION_TYPE) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (static::SQUARE_TRANSITION_TYPE === $transitionType)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above comment
|
||
protected function isSquareTransitionType() | ||
{ | ||
return $this->transitionType == static::SQUARE_TRANSITION_TYPE; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not ===
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok will change
$code[] = "agent {$transition->getName()}"; | ||
} | ||
} | ||
foreach ($definition->getTransitions() as $transition) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It feels like alot of complexity comparing to the GraphvizDumper, isn't in the class something you could re-use to get arrays and then transform them directly ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really sure I get what you want me to do. I agree it is not really straightforward but it is an efficient way to manage both TransitionType, GraphvizDumper as 2 classes to do that. I did not see the value for the PlantUML one, and I still don't see it. (but I would love to have your opinion)
I could do that in another method and then merge arrays... is it what you would like?.
Let me know!
Thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was just thinking on how much this adds complexity. I guess if merging the arrays cost more in performance than what you are doing here let's keep this. (I think it will be anyway).
I just wanted to know more about this ;).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
I have updated the PR and rebased. Not sure why the tests are failing I think it is not related to this code, |
|
||
public function __construct($transitionType = null) | ||
{ | ||
if ($transitionType === static::SQUARE_TRANSITION_TYPE) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should use yoda style, btw I don't know if it's really needed to do this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- yoda style done.
- it is a way to kind of enforcing the 2 types and those 2 type only the default one or
square
It would work without, but the value oftransitionType
could be inconsistent. Let me know your thoughts
|
||
protected function isSquareTransitionType() | ||
{ | ||
return $this->transitionType === static::SQUARE_TRANSITION_TYPE; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yoda style please.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
if (isset($options['name'])) { | ||
$code[] = "title {$options['name']}"; | ||
} | ||
if (isset($options['skinparams']) && count($options['skinparams']) > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you need to count here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
correct I replaced with is_array
to ensure the foreach won't fail if someone send something else
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some minor comments, but great improvment thanks !
updated @Simperfit (we are almost there ;) ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I let few comments on the Command Class. It seems you did not test it on real
project :/
And I followed you doc and it does not work. the program open a dialog windows
where I'm supposed to select a folder. I'm a bit lost.
Finally, I'm not sure if plantuml is really mainstream. By default the website
is in French :/ http://plantuml.com/
So for now I'm not sure we want this support in the Core. What do others think?
@@ -19,6 +19,8 @@ | |||
use Symfony\Component\Workflow\Dumper\GraphvizDumper; | |||
use Symfony\Component\Workflow\Dumper\StateMachineGraphvizDumper; | |||
use Symfony\Component\Workflow\Marking; | |||
use Symfony\Component\Console\Input\InputOption; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Input Option Is already imported.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed.
@@ -19,6 +19,8 @@ | |||
use Symfony\Component\Workflow\Dumper\GraphvizDumper; | |||
use Symfony\Component\Workflow\Dumper\StateMachineGraphvizDumper; | |||
use Symfony\Component\Workflow\Marking; | |||
use Symfony\Component\Console\Input\InputOption; | |||
use Symfony\Component\Workflow\Dumper\PlantUmlDumper; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you sort all use
s?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
@@ -39,13 +41,23 @@ protected function configure() | |||
new InputArgument('name', InputArgument::REQUIRED, 'A workflow name'), | |||
new InputArgument('marking', InputArgument::IS_ARRAY, 'A marking (a list of places)'), | |||
new InputOption('label', 'l', InputArgument::OPTIONAL, 'Labels a graph'), | |||
new InputOption('format', null, InputArgument::OPTIONAL, 'The dump format', 'dot'), | |||
new InputOption( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't do that in Symfony. All arguments should be on one line..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alright, that is fixed.
@@ -39,13 +41,23 @@ protected function configure() | |||
new InputArgument('name', InputArgument::REQUIRED, 'A workflow name'), | |||
new InputArgument('marking', InputArgument::IS_ARRAY, 'A marking (a list of places)'), | |||
new InputOption('label', 'l', InputArgument::OPTIONAL, 'Labels a graph'), | |||
new InputOption('format', null, InputArgument::OPTIONAL, 'The dump format', 'dot'), | |||
new InputOption( | |||
'transition', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
puml_transition_format
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed.
new InputOption( | ||
'transition', | ||
null, | ||
InputArgument::OPTIONAL, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is wrong:
- It's an option, not an arguement
- The value is required
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
correct, fixed.
|
||
%command.full_name% <workflow name> | dot -Tpng > workflow.png | ||
<info>DOT</info>: %command.full_name% <workflow name> | dot -Tpng > workflow.png | ||
<info>PUML</info>: %command.full_name% <workflow name> --format=puml -p | java -jar plantuml.jar > workflow.png |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is -p
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is a typo (not present in the PR doc) the -p
, as mentioned in the PR doc is for piping
. But it is for plantuml.jar... not for the command. I have fixed that too.
@@ -39,13 +41,23 @@ protected function configure() | |||
new InputArgument('name', InputArgument::REQUIRED, 'A workflow name'), | |||
new InputArgument('marking', InputArgument::IS_ARRAY, 'A marking (a list of places)'), | |||
new InputOption('label', 'l', InputArgument::OPTIONAL, 'Labels a graph'), | |||
new InputOption('format', null, InputArgument::OPTIONAL, 'The dump format', 'dot'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"The dump format [dot|puml]"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
format is a bad name because it's already used in the --help command.
So bin/console workflow:dump article --format=puml -h
do not work anymore
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch I have renamed by dump_format
} else { | ||
throw new \InvalidArgumentException(sprintf('No service found for "workflow.%1$s" nor "state_machine.%1$s".', $serviceId)); | ||
} | ||
|
||
if ('puml' === $format) { | ||
$dumper = new PlantUmlDumper($transitionType); | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use an else if here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok done.
/** | ||
* PlantUmlDumper dumps a workflow as a PlantUML file. | ||
* | ||
* You can convert the generated dot file with the plantuml.jar utility (http://plantuml.com/): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose it does not generate a dot file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that is correct, I have pushed the correction. thx!
knh4RrvOKzxZfLV3s0rs_R_1SdYt3VxeQ1_y2_W2 | ||
}'; | ||
const INITIAL = 'initial'; | ||
const MARKED = 'marked'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't some of these be private constants ?
|
||
private function isSquareTransitionType(): bool | ||
{ | ||
return static::SQUARE_TRANSITION_TYPE === $this->transitionType; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use self::
to access constant. There is no reason to make them an extension point by allowing changing their values (and the code would not work anyway in such case, due to other places)
return $start; | ||
} | ||
|
||
return $start.static::SYMFONY_LOGO.PHP_EOL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self:
here as well
return $end; | ||
} | ||
|
||
return PHP_EOL.'footer \nGenerated by <$sf_logo> **Workflow Component** and **PlantUML**'.$end; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure about the \n
here, which is not a newline char ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes I think so, the \n
is working as expected.
The dump of the workflow in #24705 (comment) looks confusing to me. It looks like there are 2 independant |
Oh @stof Is totally right. This PR could not be merged in this state. |
The current dumper is fine for the case of state machines though |
@stof thank you I have updated the code. From my point of view, I don't find it that confusing as I know that I can have only one You said:
But here: https://symfony.com/doc/current/workflow/state-machines.html The PR is aiming to let the choice to the user to dump it with On the cases provided in the doc and on the Pull Request: https://symfony.com/doc/current/workflow/state-machines.html Blog Publishing: https://symfony.com/doc/current/workflow/usage.html Article: https://github.com/lyrixx/SFLive-Paris2016-Workflow/blob/master/config/packages/workflow.yaml#L3 I think that is working, I am not sure what you are expecting, I see at least 3 options in which we could go:
Let me know |
It's definitively the way to go ;) |
hey @lyrixx @stof I have done the option 1/ For the sake of my understanding, I would love if you could you explain why "arrows" are not valid sometimes? In this example, for instance, it feels simpler to have arrows. But I would understand if the reason is to force a kind of consistency for each type. Let me know! |
ok makes sense ;-) all good to merge then maybe ;-) |
Thank you @Plopix. |
…d (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:  With `square` as transition, it gives you that:  Hope you will find that interesting! Commits ------- 1497d36 Add option to the workflow:dump command to allow PlantUML format dump
👏 Thanks for your hard work on this feature. I just tested it and it works very well. |
This PR was submitted for the 4.0 branch but it was merged into the master branch instead (closes #9220). Discussion ---------- [Workflow] PlantUML Dump documentation Documentation related to symfony/symfony#24705 This PR aims to explain that the PlantUML dump format is available. Platform.sh URL: http://pr-9220-x7nzdnq-6qmocelev2lwe.eu.platform.sh/workflow/dumping-workflows.html Commits ------- b62d961 [Workflow] PlantUML Dump documentation
Hello,
workflow:dump
exports workflows indot
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 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 and plenty of integration of this format.
This PR adds 2 options
--dump-format=puml
option to theworkflow:dump
command to generate the workflows in PlantUML.The conversion requires the PlantUML JAR, and can be used like that:
Here is an example with
pull_request
workflow of the documentation (with no style and no marking):As PlantUML let us define styles, I have provided some by default that the user can override.
Adding some marking:
will give us:
Which gives you that:

With

square
as transition, it gives you that:Hope you will find that interesting!