diff --git a/src/ProcessEngine.php b/src/ProcessEngine.php index f51c4ac..bd75e2b 100644 --- a/src/ProcessEngine.php +++ b/src/ProcessEngine.php @@ -175,6 +175,7 @@ private function doProceed(Token $token) } $first = true; + /** @var Transition $transition */ foreach ($transitions as $transition) { $this->log('Next transition: %s -> %s', $transition->getFrom() ? $transition->getFrom()->getLabel() : 'start', @@ -185,12 +186,20 @@ private function doProceed(Token $token) $first = false; $token->addTransition(TokenTransition::createFor($transition, $tokenTransition->getWeight())); + foreach ($transition->getTokenValues() as $key => $value) { + set_value($token, $key, $value); + } + $this->transition($token); } else { $newToken = $this->forkProcessToken($token); $newToken->addTransition(TokenTransition::createFor($transition, $transition->getWeight())); $newToken->getCurrentTransition()->setWeight($tokenTransition->getWeight()); + foreach ($transition->getTokenValues() as $key => $value) { + set_value($newToken, $key, $value); + } + $this->transition($newToken); } } diff --git a/src/Transition.php b/src/Transition.php index 605ddee..d4aed2e 100644 --- a/src/Transition.php +++ b/src/Transition.php @@ -20,12 +20,19 @@ class Transition */ private $_process; + /** + * @var array + */ + private $tokenValues; + public function __construct() { $this->setId(Uuid::generate()); $this->setWeight(1); $this->setAsync(false); $this->setActive(true); + + $this->tokenValues = []; } /** @@ -166,4 +173,14 @@ public function getState(): string { return get_value($this, 'state'); } + + public function setTokenValues(array $values): void + { + $this->tokenValues = $values; + } + + public function getTokenValues(): array + { + return $this->tokenValues; + } } diff --git a/src/Visual/BuildDigraphScript.php b/src/Visual/BuildDigraphScript.php index ff30366..c7d2c45 100644 --- a/src/Visual/BuildDigraphScript.php +++ b/src/Visual/BuildDigraphScript.php @@ -74,7 +74,7 @@ public function build(Graph $graph): string } } -//dump($digraph->render());die; + return $digraph->render(); } } diff --git a/src/Visual/VisualizeFlow.php b/src/Visual/VisualizeFlow.php index 6d4f8e6..7be5025 100644 --- a/src/Visual/VisualizeFlow.php +++ b/src/Visual/VisualizeFlow.php @@ -118,7 +118,7 @@ public function display(Graph $graph) private function createVertex(Graph $graph, Node $node) { /** @var Options $options */ - $options = get_object($node, 'visual', Options::class) ?: new Options(); + $options = get_object($node, 'option', Options::class) ?: new Options(); $vertex = $graph->createVertex($node->getId()); $vertex->setAttribute('graphviz.label', $node->getLabel() ?: $node->getId()); $vertex->setAttribute('graphviz.id', $node->getId()); @@ -131,6 +131,9 @@ private function createVertex(Graph $graph, Node $node) case 'gateway': $shape = 'diamond'; break; + case 'event': + $shape = 'circle'; + break; default: $shape = 'box'; } @@ -157,7 +160,7 @@ private function createStartTransition(Graph $graph, Vertex $from, Transition $t $edge->setAttribute('alom.graphviz', [ 'label' => $transition->getName(), - 'id' => $transition->getId(), + 'id' => sprintf('%s->%s', $from->getId(), $to->getId()), ]); } @@ -171,13 +174,15 @@ private function createEndTransition(Graph $graph, Vertex $to, Transition $trans $edge = $from->createEdgeTo($to); } - $edge->setAttribute('graphviz.label', $transition->getName()); - $edge->setAttribute('graphviz.id', $transition->getId()); - $edge->setAttribute('pvm.transition_id', $transition->getId()); + $id = sprintf('%s->%s', $from->getId(), $to->getId()); + + $edge->setAttribute('graphviz.label', $id); + $edge->setAttribute('graphviz.id', $id); + $edge->setAttribute('pvm.transition_id', $id); $edge->setAttribute('alom.graphviz', [ 'label' => $transition->getName(), - 'id' => $transition->getId(), + 'id' => $id, ]); } @@ -189,10 +194,7 @@ private function createMiddleTransition(Graph $graph, Transition $transition) $edge = $from->createEdgeTo($to); $edge->setAttribute('pvm.transition_id', $transition->getId()); $edge->setAttribute('graphviz.id', $transition->getId()); - $edge->setAttribute( - 'graphviz.label', - $transition->getName() - ); + $edge->setAttribute('graphviz.label', $transition->getName()); $edge->setAttribute('alom.graphviz', [ 'id' => $transition->getId(),