Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f28b4e3

Browse filesBrowse files
committed
[Workflow] Add a link to mermaid.live from the profiler
1 parent 79fa5f2 commit f28b4e3
Copy full SHA for f28b4e3

File tree

2 files changed

+38
-22
lines changed
Filter options

2 files changed

+38
-22
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/workflow.html.twig
+14-11
Original file line numberDiff line numberDiff line change
@@ -137,20 +137,22 @@
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,
145-
'fontFamily': 'var(--font-family-system)',
146-
'fontSize': 'var(--font-size-body)',
147+
fontFamily: 'var(--font-family-system)',
148+
fontSize: 'var(--font-size-body)',
147149
// the properties below don't support CSS variables
148-
'primaryColor': isDarkMode ? 'lightsteelblue' : 'aliceblue',
149-
'primaryTextColor': isDarkMode ? '#000' : '#000',
150-
'primaryBorderColor': isDarkMode ? 'steelblue' : 'lightsteelblue',
151-
'lineColor': isDarkMode ? '#939393' : '#d4d4d4',
152-
'secondaryColor': isDarkMode ? 'lightyellow' : 'lightyellow',
153-
'tertiaryColor': isDarkMode ? 'lightSalmon' : 'lightSalmon',
150+
primaryColor: isDarkMode ? 'lightsteelblue' : 'aliceblue',
151+
primaryTextColor: isDarkMode ? '#000' : '#000',
152+
primaryBorderColor: isDarkMode ? 'steelblue' : 'lightsteelblue',
153+
lineColor: isDarkMode ? '#939393' : '#d4d4d4',
154+
secondaryColor: isDarkMode ? 'lightyellow' : 'lightyellow',
155+
tertiaryColor: isDarkMode ? 'lightSalmon' : 'lightSalmon',
154156
}
155157
});
156158
@@ -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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Workflow/DataCollector/WorkflowDataCollector.php
+24-11
Original file line numberDiff line numberDiff line change
@@ -88,33 +88,46 @@ public function getCallsCount(): int
8888
return $i;
8989
}
9090

91+
public function hash(string $string): string
92+
{
93+
return hash('xxh128', $string);
94+
}
95+
96+
public function buildMermaidLink(string $name): string
97+
{
98+
$payload = [
99+
'code' => $this->data['workflows'][$name]['dump'],
100+
'mermaid' => '{"theme": "default"}',
101+
'autoSync' => false,
102+
];
103+
104+
$compressed = zlib_encode(json_encode($payload), ZLIB_ENCODING_DEFLATE);
105+
106+
$suffix = rtrim(strtr(base64_encode($compressed), '+/', '-_'), '=');
107+
108+
return "https://mermaid.live/edit#pako:{$suffix}";
109+
}
110+
91111
protected function getCasters(): array
92112
{
93113
return [
94114
...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-
);
115+
TransitionBlocker::class => static function ($v, array $a, Stub $s) {
116+
unset($a[\sprintf(Caster::PATTERN_PRIVATE, $v::class, 'code')]);
117+
unset($a[\sprintf(Caster::PATTERN_PRIVATE, $v::class, 'parameters')]);
100118

101119
$s->cut += 2;
102120

103121
return $a;
104122
},
105-
Marking::class => function ($v, array $a, Stub $s, $isNested) {
123+
Marking::class => static function ($v, array $a) {
106124
$a[Caster::PREFIX_VIRTUAL.'.places'] = array_keys($v->getPlaces());
107125

108126
return $a;
109127
},
110128
];
111129
}
112130

113-
public function hash(string $string): string
114-
{
115-
return hash('xxh128', $string);
116-
}
117-
118131
private function getEventListeners(WorkflowInterface $workflow): array
119132
{
120133
$listeners = [];

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.