Skip to content

Instantly share code, notes, and snippets.

@huanle0610
Created April 24, 2016 23:17
Show Gist options
  • Save huanle0610/0d1da327a9c2c891829943ed0800c3e6 to your computer and use it in GitHub Desktop.
Save huanle0610/0d1da327a9c2c891829943ed0800c3e6 to your computer and use it in GitHub Desktop.
Show phprbac permissions and roles in PlantUML
<?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);
@huanle0610
Copy link
Author

huanle0610 commented Apr 24, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment