-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Workflow] Made GraphvizDumper supports StateMachine #20497
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,7 +84,7 @@ private function findTransitions(Definition $definition) | |
$transitions = array(); | ||
|
||
foreach ($definition->getTransitions() as $transition) { | ||
$transitions[] = array( | ||
$transitions[$transition->getName()] = array( | ||
'attributes' => array('shape' => 'box', 'regular' => true), | ||
'name' => $transition->getName(), | ||
); | ||
|
@@ -126,21 +126,20 @@ private function addTransitions(array $transitions) | |
private function findEdges(Definition $definition) | ||
{ | ||
$dotEdges = array(); | ||
$getEdge = function ($from, $to, $direction) use (&$dotEdges) { | ||
$dotEdges[$from.$to.$direction] = array( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This kind of "hash" could collide. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They should, this is the point of it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the thing is that your dumping of the StateMachine graph does not represent the workflow being defined by the state machine, as you represent a single transition with multiple input and output instead of several transitions (the fact that the DI config of the StateMachine allows to define these transitions in a shorted way by grouping them does not mean they are the same transition in the StateMachine) Btw, this is why I said we should have another dumper being tailored only at state machines, and dumping them into a graph being more readable. This graph would represent transitions as edges on the graph (which is not possible in generic workflows, as transitions can have multiple input and output). But I would make this another dumper, or an option in this dumper, because dumping the StateMachine as a generic workflow graph can be useful too. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alright! Thank you again for your explanation, I'll work on that soon! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
👍 |
||
'from' => $from, | ||
'to' => $to, | ||
'direction' => $direction, | ||
); | ||
}; | ||
|
||
foreach ($definition->getTransitions() as $transition) { | ||
foreach ($transition->getFroms() as $from) { | ||
$dotEdges[] = array( | ||
'from' => $from, | ||
'to' => $transition->getName(), | ||
'direction' => 'from', | ||
); | ||
$getEdge($from, $transition->getName(), 'from'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok l'll change it to |
||
} | ||
foreach ($transition->getTos() as $to) { | ||
$dotEdges[] = array( | ||
'from' => $transition->getName(), | ||
'to' => $to, | ||
'direction' => 'to', | ||
); | ||
$getEdge($transition->getName(), $to, 'to'); | ||
} | ||
} | ||
|
||
|
@@ -152,10 +151,11 @@ private function addEdges($edges) | |
$code = ''; | ||
|
||
foreach ($edges as $edge) { | ||
$from = 'from' === $edge['direction']; | ||
$code .= sprintf(" %s_%s -> %s_%s [style=\"solid\"];\n", | ||
'from' === $edge['direction'] ? 'place' : 'transition', | ||
$from ? 'place' : 'transition', | ||
$this->dotize($edge['from']), | ||
'from' === $edge['direction'] ? 'transition' : 'place', | ||
$from ? 'transition' : 'place', | ||
$this->dotize($edge['to']) | ||
); | ||
} | ||
|
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 wrong to me. Transition names are not unique in the definition (the only requirement is that transition starting from a given node have unique names)
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.
@stof This is what this key is about, removing duplicated transition names, since they generate useless code in the
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.
If they have the same name, they have different from/to, so they should both be rendered on the graph separately (otherwise, the graph will lie).
Btw, for a finite state machine, we could change the graph to render transitions as edges directly (optionally, as rendering the graph in workflow mode is still useful), as they are known to have a single from and a single to
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 not true for the way state machines have been implemented. It splits the transition that has many tos in many transitions with the same name.
See https://github.com/symfony/symfony/blob/master/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php#L416.
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.
@HeahDude But this class is also able to dump Workflow graph.