mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
97 lines
2.6 KiB
PHP
97 lines
2.6 KiB
PHP
<?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);
|
|
}
|
|
}
|
|
|
|
|
|
|