Skip to content

Commit

Permalink
bug #51214 [Workflow] Use TRANSITION_TYPE_WORKFLOW for rendering work…
Browse files Browse the repository at this point in the history
…flow in profiler (lyrixx)

This PR was merged into the 6.4 branch.

Discussion
----------

[Workflow] Use TRANSITION_TYPE_WORKFLOW for rendering workflow in profiler

| Q             | A
| ------------- | ---
| Branch?       | 6.4
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Tickets       |
| License       | MIT
| Doc PR        |

---

This one is a bit special.

Usually a state machine render like this:

![image](https://github.com/symfony/symfony/assets/408368/50f45620-aa88-4fc8-97c2-1049c08b2ee7)

As you can see, **transitions** (ex: `start_process`) are not real nodes. They are arrows.

And it's not possible to attach events on arrows, only on nodes.

That's why I add this hybrid mode, where state machine are rendered like a workflow. It means transitions are renderered as node:

![image](https://github.com/symfony/symfony/assets/408368/80f6731a-2d02-4eab-be2d-77ab67495006)

Now, we can attach event on transition nodes.

Commits
-------

0cdf2b8 [Workflow] Use TRANSITION_TYPE_WORKFLOW for rendering workflow in profiler
  • Loading branch information
fabpot committed Aug 11, 2023
2 parents 15d7b1b + 0cdf2b8 commit d6d233b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use Symfony\Component\HttpKernel\DataCollector\DataCollector;
use Symfony\Component\HttpKernel\DataCollector\LateDataCollectorInterface;
use Symfony\Component\Workflow\Dumper\MermaidDumper;
use Symfony\Component\Workflow\StateMachine;

/**
* @author Grégoire Pineau <lyrixx@lyrixx.info>
Expand All @@ -35,8 +34,9 @@ public function collect(Request $request, Response $response, \Throwable $except
public function lateCollect(): void
{
foreach ($this->workflows as $workflow) {
$type = $workflow instanceof StateMachine ? MermaidDumper::TRANSITION_TYPE_STATEMACHINE : MermaidDumper::TRANSITION_TYPE_WORKFLOW;
$dumper = new MermaidDumper($type);
// We always use a workflow type because we want to mermaid to
// create a node for transitions
$dumper = new MermaidDumper(MermaidDumper::TRANSITION_TYPE_WORKFLOW);
$this->data['workflows'][$workflow->getName()] = [
'dump' => $dumper->dump($workflow->getDefinition()),
];
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Workflow/Dumper/MermaidDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public function dump(Definition $definition, Marking $marking = null, array $opt
$to = $placeNameMap[$to];

if (self::TRANSITION_TYPE_STATEMACHINE === $this->transitionType) {
$transitionOutput = $this->styleStatemachineTransition($from, $to, $transitionLabel, $transitionMeta);
$transitionOutput = $this->styleStateMachineTransition($from, $to, $transitionLabel, $transitionMeta);
} else {
$transitionOutput = $this->styleWorkflowTransition($from, $to, $transitionId, $transitionLabel, $transitionMeta);
}
Expand Down Expand Up @@ -196,7 +196,7 @@ private function validateTransitionType(string $transitionType): void
}
}

private function styleStatemachineTransition(string $from, string $to, string $transitionLabel, array $transitionMeta): array
private function styleStateMachineTransition(string $from, string $to, string $transitionLabel, array $transitionMeta): array
{
$transitionOutput = [sprintf('%s-->|%s|%s', $from, str_replace("\n", ' ', $this->escape($transitionLabel)), $to)];

Expand Down

0 comments on commit d6d233b

Please sign in to comment.