-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
157 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/Symfony/Bundle/FrameworkBundle/Resources/config/workflow_debug.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\DependencyInjection\Loader\Configurator; | ||
|
||
use Symfony\Component\Workflow\DataCollector\WorkflowDataCollector; | ||
|
||
return static function (ContainerConfigurator $container) { | ||
$container->services() | ||
->set('data_collector.workflow', WorkflowDataCollector::class) | ||
->tag('data_collector', [ | ||
'template' => '@WebProfiler/Collector/workflow.html.twig', | ||
'id' => 'workflow', | ||
]) | ||
->args([ | ||
tagged_iterator('workflow', 'name'), | ||
]) | ||
; | ||
}; |
64 changes: 64 additions & 0 deletions
64
src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/workflow.html.twig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
{% extends '@WebProfiler/Profiler/layout.html.twig' %} | ||
|
||
{% block menu %} | ||
<span class="label {{ collector.dumps|length == 0 ? 'disabled' }}"> | ||
<span class="icon"> | ||
{{ source('@WebProfiler/Icon/workflow.svg') }} | ||
</span> | ||
<strong>Workflow</strong> | ||
</span> | ||
{% endblock %} | ||
|
||
{% block panel %} | ||
<h2>Workflow</h2> | ||
|
||
{% if collector.dumps|length == 0 %} | ||
<div class="empty empty-panel"> | ||
<p>There are no workflows configured.</p> | ||
</div> | ||
{% else %} | ||
<script type="module"> | ||
import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.esm.min.mjs'; | ||
// We do not load all mermaid diagrams at once, but only when the tab is opened | ||
// This is because mermaid diagrams are in a tab, and cannot be renderer with a | ||
// "good size" if they are not visible | ||
document.addEventListener('DOMContentLoaded', () => { | ||
document.querySelectorAll('.tab').forEach((el) => { | ||
const observer = new MutationObserver(() => { | ||
if (!el.classList.contains('block')) { | ||
return; | ||
} | ||
mermaid.initialize({ | ||
startOnLoad: false, | ||
flowchart: { useMaxWidth: false }, | ||
securityLevel: 'loose', | ||
}); | ||
const mEl = el.querySelector('.sf-mermaid'); | ||
if (mEl.dataset.processed) { | ||
return; | ||
} | ||
console.log(mEl); | ||
mermaid.run({ | ||
nodes: [mEl], | ||
}); | ||
}); | ||
observer.observe(el, { attributeFilter: ['class'] }); | ||
}); | ||
}); | ||
</script> | ||
|
||
<h2>Definitions</h2> | ||
<div class="sf-tabs js-tabs"> | ||
{% for name, dump in collector.dumps %} | ||
<div class="tab"> | ||
<h3 class="tab-title">{{ name }}</h3> | ||
<div class="tab-content"> | ||
<pre class="sf-mermaid"> | ||
{{ dump|raw }} | ||
</pre> | ||
</div> | ||
</div> | ||
{% endfor %} | ||
</div> | ||
{% endif %} | ||
{% endblock %} |
1 change: 1 addition & 0 deletions
1
src/Symfony/Bundle/WebProfilerBundle/Resources/views/Icon/workflow.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
59 changes: 59 additions & 0 deletions
59
src/Symfony/Component/Workflow/DataCollector/WorkflowDataCollector.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Workflow\DataCollector; | ||
|
||
use Symfony\Component\DependencyInjection\ServiceLocator; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
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> | ||
*/ | ||
final class WorkflowDataCollector extends DataCollector implements LateDataCollectorInterface | ||
{ | ||
public function __construct( | ||
private readonly iterable $workflows, | ||
) { | ||
} | ||
|
||
public function collect(Request $request, Response $response, \Throwable $exception = null) | ||
{ | ||
} | ||
|
||
public function lateCollect() | ||
{ | ||
foreach ($this->workflows as $workflow) { | ||
$type = $workflow instanceof StateMachine ? MermaidDumper::TRANSITION_TYPE_STATEMACHINE : MermaidDumper::TRANSITION_TYPE_WORKFLOW; | ||
$dumper = new MermaidDumper($type); | ||
$this->data['dumps'][$workflow->getName()] = $dumper->dump($workflow->getDefinition()); | ||
} | ||
} | ||
|
||
public function getName() | ||
{ | ||
return 'workflow'; | ||
} | ||
|
||
public function reset(): void | ||
{ | ||
$this->data = []; | ||
} | ||
|
||
public function getDumps(): array | ||
{ | ||
return $this->data['dumps'] ?? []; | ||
} | ||
} |