Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add route, template and export (#218)
- Loading branch information
1 parent
6d3fc82
commit 2618975
Showing
3 changed files
with
84 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Frosh\Tools\Components\StateMachines; | ||
|
||
use Shopware\Core\System\StateMachine\StateMachineEntity; | ||
use Twig\Environment; | ||
use Twig\Loader\FilesystemLoader; | ||
|
||
final class Mermaid implements ExportInterface | ||
{ | ||
private const DEFAULT_PATH = __DIR__ . '/../../Resources/views/administration/mermaid'; | ||
|
||
private readonly Environment $twig; | ||
|
||
public function __construct() | ||
{ | ||
$path = realpath(self::DEFAULT_PATH); | ||
if (!\is_string($path)) { | ||
throw new \RuntimeException('Could not find default path for PlantUML templates'); | ||
} | ||
|
||
$this->twig = new Environment(new FilesystemLoader($path)); | ||
} | ||
|
||
public function export(StateMachineEntity $stateMachine, string $title = ''): string | ||
{ | ||
return $this->twig->render('state-machine.html.twig', [ | ||
'title' => $title, | ||
'initialState' => $stateMachine->getInitialState(), | ||
'states' => $stateMachine->getStates()?->getElements(), | ||
'transitions' => $stateMachine->getTransitions()?->getElements(), | ||
]); | ||
} | ||
} |
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
18 changes: 18 additions & 0 deletions
18
src/Resources/views/administration/mermaid/state-machine.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,18 @@ | ||
flowchart TD | ||
{{ 'START_STATE[Start state] -->' }} {{ initialState.getId() }} | ||
|
||
{% for state in states %} | ||
{{ state.getId() }}({{ state.getName()|replace({'(': "", ')': ""}) }}) | ||
{% set temp %}{% apply spaceless %} | ||
{% for transition in transitions %} | ||
{% if transition.getFromStateId() == state.getId() and transition.getActionName() != 'reopen' %}yes{% else %}{% endif %} | ||
{% endfor %}{% endapply %} | ||
{% endset %} | ||
{% if temp|trim is empty %} | ||
{{ state.getId() }} {{ '--> FINAL_STATE[Final state]' }} | ||
{% endif %} | ||
{% endfor %} | ||
|
||
{% for transition in transitions %} | ||
{{ transition.getFromStateId() }} {{ '--' }} {{ transition.getActionName() }} {{ '-->' }} {{ transition.getToStateId() }} | ||
{% endfor %} |