Created
April 24, 2016 23:17
-
-
Save huanle0610/0d1da327a9c2c891829943ed0800c3e6 to your computer and use it in GitHub Desktop.
Show phprbac permissions and roles in PlantUML
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
<?php | |
require_once 'autoload.php'; | |
require_once 'src/PhpRbac/Rbac.php'; | |
$rbac = new \PhpRbac\Rbac(); | |
function getPermissionUml(&$rbac) | |
{ | |
$arr = Jf::sql('select * from phprbac_permissions'); | |
echo "title Permissions", "\n"; | |
foreach($arr as $row) | |
{ | |
$p = $rbac->Permissions->parentNode($row['ID']); | |
$title = getChartTitle($row); | |
$itemType = (($row['Rght'] - $row['Lft']) === 1) ? 'entity' : 'storage'; | |
echo $itemType, " \"", $row['Title'], " ", $row['ID'], "\" as ",$title, "\n"; | |
if($p) | |
{ | |
$parent_title = getChartTitle($p); | |
echo $title, " -u-> ", $parent_title , "\n"; | |
} | |
} | |
} | |
function getRoleUml(&$rbac) | |
{ | |
$arr = Jf::sql('select * from phprbac_roles'); | |
echo "title Roles", "\n"; | |
foreach($arr as $row) | |
{ | |
$p = $rbac->Roles->parentNode($row['ID']); | |
$title = getChartTitle($row); | |
$itemType = (($row['Rght'] - $row['Lft']) === 1) ? 'entity' : 'storage'; | |
echo $itemType, " \"", $row['Title'], "\" as ",$title, "\n"; | |
if($p) | |
{ | |
$parent_title = getChartTitle($p); | |
echo $parent_title," -d-> ",$title , "\n"; | |
} | |
} | |
} | |
function getChartTitle($row) | |
{ | |
$title = str_replace(" ", '_', $row['Title']); | |
return sprintf("%s_%d", $title, $row['ID']); | |
} | |
getPermissionUml($rbac); | |
//getRoleUml($rbac); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Paste text here: http://plantuml.com/plantuml/form
![Permissions](https://camo.githubusercontent.com/415c3aebb20b6a6d891264ebe9b718a97bcc35da44659d3762c2d5001de4f11c/687474703a2f2f7777342e73696e61696d672e636e2f6d77313032342f36326461626636366a77316633386c617277626a626a323073783062343737352e6a7067)