Skip to content

Commit cf57a8d

Browse files
committed
[Workflow] Add a link to mermaid.live from the profiler
1 parent 79fa5f2 commit cf57a8d

File tree

2 files changed

+45
-25
lines changed

2 files changed

+45
-25
lines changed

src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/workflow.html.twig

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,12 @@
137137
{{ source('@WebProfiler/Script/Mermaid/mermaid-flowchart-v2.min.js') }}
138138
const isDarkMode = document.querySelector('body').classList.contains('theme-dark');
139139
mermaid.initialize({
140-
flowchart: { useMaxWidth: false },
140+
flowchart: {
141+
useMaxWidth: true,
142+
},
141143
securityLevel: 'loose',
142-
'theme': 'base',
143-
'themeVariables': {
144+
theme: 'base',
145+
themeVariables: {
144146
darkMode: isDarkMode,
145147
'fontFamily': 'var(--font-family-system)',
146148
'fontSize': 'var(--font-size-body)',
@@ -275,6 +277,7 @@
275277
click {{ nodeId }} showNodeDetails{{ collector.hash(name) }}
276278
{% endfor %}
277279
</pre>
280+
<a href="{{ collector.buildMermaidLink(name) }}">View on mermaid.live</a>
278281

279282
<h3>Calls</h3>
280283
<table>

src/Symfony/Component/Workflow/DataCollector/WorkflowDataCollector.php

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -88,28 +88,6 @@ public function getCallsCount(): int
8888
return $i;
8989
}
9090

91-
protected function getCasters(): array
92-
{
93-
return [
94-
...parent::getCasters(),
95-
TransitionBlocker::class => function ($v, array $a, Stub $s, $isNested) {
96-
unset(
97-
$a[\sprintf(Caster::PATTERN_PRIVATE, $v::class, 'code')],
98-
$a[\sprintf(Caster::PATTERN_PRIVATE, $v::class, 'parameters')],
99-
);
100-
101-
$s->cut += 2;
102-
103-
return $a;
104-
},
105-
Marking::class => function ($v, array $a, Stub $s, $isNested) {
106-
$a[Caster::PREFIX_VIRTUAL.'.places'] = array_keys($v->getPlaces());
107-
108-
return $a;
109-
},
110-
];
111-
}
112-
11391
public function hash(string $string): string
11492
{
11593
return hash('xxh128', $string);
@@ -163,6 +141,45 @@ private function getEventListeners(WorkflowInterface $workflow): array
163141
return $listeners;
164142
}
165143

144+
public function buildMermaidLink(string $name)
145+
{
146+
$payload = [
147+
'code' => $this->data['workflows'][$name]['dump'],
148+
'mermaid' => json_encode([
149+
'theme' => 'default',
150+
]),
151+
'autoSync' => false,
152+
];
153+
154+
$compressed = zlib_encode(json_encode($payload), ZLIB_ENCODING_DEFLATE);
155+
156+
$suffix = rtrim(strtr(base64_encode($compressed), '+/', '-_'), '=');
157+
158+
return "https://mermaid.live/edit#pako:{$suffix}";
159+
}
160+
161+
protected function getCasters(): array
162+
{
163+
return [
164+
...parent::getCasters(),
165+
TransitionBlocker::class => function ($v, array $a, Stub $s, $isNested) {
166+
unset(
167+
$a[\sprintf(Caster::PATTERN_PRIVATE, $v::class, 'code')],
168+
$a[\sprintf(Caster::PATTERN_PRIVATE, $v::class, 'parameters')],
169+
);
170+
171+
$s->cut += 2;
172+
173+
return $a;
174+
},
175+
Marking::class => function ($v, array $a, Stub $s, $isNested) {
176+
$a[Caster::PREFIX_VIRTUAL.'.places'] = array_keys($v->getPlaces());
177+
178+
return $a;
179+
},
180+
];
181+
}
182+
166183
private function summarizeListener(callable $callable, ?string $eventName = null, ?Transition $transition = null): array
167184
{
168185
$extra = [];

0 commit comments

Comments
 (0)