Skip to content

[Security][SecurityBundle] Dump role hierarchy as mermaid chart #61034

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: 7.4
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
refactor: update MermaidDumper to accept direction as a parameter in …
…dump method
  • Loading branch information
damienfern committed Jul 18, 2025
commit 96d1fdaeae5dcbfcb8f654bc3ceeeefdf6b4b499
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return Command::FAILURE;
}

$dumper = new MermaidDumper(MermaidDirectionEnum::from($direction));
$mermaidOutput = $dumper->dump($this->roleHierarchy);
$dumper = new MermaidDumper();
$mermaidOutput = $dumper->dump($this->roleHierarchy, MermaidDirectionEnum::from($direction));

$output->writeln($mermaidOutput);

Expand Down
12 changes: 4 additions & 8 deletions src/Symfony/Component/Security/Core/Dumper/MermaidDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,21 @@
*/
class MermaidDumper
{
public function __construct(
private readonly MermaidDirectionEnum $direction = MermaidDirectionEnum::TOP_TO_BOTTOM,
) {
}

/**
* Dumps the role hierarchy as a Mermaid flowchart.
*
* @param RoleHierarchyInterface $roleHierarchy The role hierarchy to dump
* @param MermaidDirectionEnum $direction The direction of the flowchart
*/
public function dump(RoleHierarchyInterface $roleHierarchy): string
public function dump(RoleHierarchyInterface $roleHierarchy, MermaidDirectionEnum $direction = MermaidDirectionEnum::TOP_TO_BOTTOM): string
{
$hierarchy = $this->extractHierarchy($roleHierarchy);

if (!$hierarchy) {
return "graph {$this->direction->value}\n classDef default fill:#e1f5fe;";
return "graph {$direction->value}\n classDef default fill:#e1f5fe;";
}

$output = ["graph {$this->direction->value}"];
$output = ["graph {$direction->value}"];
$allRoles = $this->getAllRoles($hierarchy);

foreach ($allRoles as $role) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public function testDumpWithDirection()
];

$roleHierarchy = new RoleHierarchy($hierarchy);
$dumper = new MermaidDumper(MermaidDirectionEnum::LEFT_TO_RIGHT);
$output = $dumper->dump($roleHierarchy);
$dumper = new MermaidDumper();
$output = $dumper->dump($roleHierarchy, MermaidDirectionEnum::LEFT_TO_RIGHT);

$this->assertStringContainsString('graph LR', $output);
}
Expand Down Expand Up @@ -92,7 +92,8 @@ public function testInvalidDirection()
{
$this->expectException(\TypeError::class);

new MermaidDumper('INVALID');
$dumper = new MermaidDumper();
$dumper->dump(new RoleHierarchy([]), 'INVALID');
}

/**
Expand All @@ -101,7 +102,8 @@ public function testInvalidDirection()
public function testValidDirections(MermaidDirectionEnum $direction)
{
$this->expectNotToPerformAssertions();
new MermaidDumper($direction);
$dumper = new MermaidDumper();
$dumper->dump(new RoleHierarchy([]), $direction);
}

public static function dataProviderValidDirection()
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy