mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
Añadido helper para crear los archivos de costantes de RBAC
This commit is contained in:
96
ci4/app/Helpers/rbac_helper.php
Normal file
96
ci4/app/Helpers/rbac_helper.php
Normal file
@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Usuarios\GroupModel;
|
||||
use App\Models\Usuarios\PermisosModel;
|
||||
|
||||
if (!function_exists('generate_php_roles_constant')) {
|
||||
function generate_php_roles_constant()
|
||||
{
|
||||
// Generate the array of keys
|
||||
$array = (new GroupModel())->getRolesList();
|
||||
|
||||
// Start of the file
|
||||
$phpCode = "<?php\n\n";
|
||||
|
||||
// Add constant name
|
||||
$phpCode .= "const SK_ROLES = [\n";
|
||||
|
||||
// Loop through the array and create constant
|
||||
// Loop through the array and create constant
|
||||
foreach ($array as $key => $values) {
|
||||
$phpCode .= " '{$key}' => [\n";
|
||||
foreach ($values as $subkey => $value) {
|
||||
$phpCode .= " '{$subkey}' => '{$value}',\n";
|
||||
}
|
||||
$phpCode .= " ],\n";
|
||||
}
|
||||
|
||||
// Close the array
|
||||
$phpCode .= "];\n";
|
||||
|
||||
// Write PHP code to a file
|
||||
$filePath = APPPATH . "Config/RBAC/roles.php";
|
||||
file_put_contents($filePath, $phpCode);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!function_exists('generate_php_permissions_constant')) {
|
||||
function generate_php_permissions_constant()
|
||||
{
|
||||
// Generate the array of keys
|
||||
$array = (new PermisosModel())->getPermissionsList();
|
||||
|
||||
// Start of the file
|
||||
$phpCode = "<?php\n\n";
|
||||
|
||||
// Add constant name
|
||||
$phpCode .= "const SK_PERMISSIONS = [\n";
|
||||
|
||||
// Loop through the array and create constant
|
||||
foreach ($array as $key => $value) {
|
||||
// Using single quotes to ensure keys/values are emitted as literals
|
||||
$phpCode .= "\t'{$key}' => '{$value}',\n";
|
||||
}
|
||||
|
||||
// Close the array
|
||||
$phpCode .= "];\n";
|
||||
|
||||
// Write PHP code to a file
|
||||
$filePath = APPPATH . "Config/RBAC/permissions.php";
|
||||
file_put_contents($filePath, $phpCode);
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('generate_php_permissions_matrix_constant')) {
|
||||
function generate_php_permissions_matrix_constant()
|
||||
{
|
||||
$matrix = (new GroupModel())->getRolesPermissionMatrix();
|
||||
|
||||
|
||||
// Start of the file
|
||||
$phpCode = "<?php\n";
|
||||
|
||||
// Add constant name
|
||||
$phpCode .= "const SK_PERMISSION_MATRIX = [\n";
|
||||
|
||||
// Loop through the array and create constant
|
||||
foreach ($matrix as $role => $permissions) {
|
||||
$phpCode .= "\t\"{$role}\" => [\n";
|
||||
foreach ($permissions as $permission) {
|
||||
$phpCode .= "\t\t\"{$permission}\",\n";
|
||||
}
|
||||
$phpCode .= "\t],\n";
|
||||
}
|
||||
// Close the array
|
||||
$phpCode .= "];\n";
|
||||
|
||||
// Write PHP code to a file
|
||||
$filePath = APPPATH . "Config/RBAC/permissionMatrix.php";
|
||||
file_put_contents($filePath, $phpCode);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user