diff --git a/ci4/app/Helpers/rbac_helper.php b/ci4/app/Helpers/rbac_helper.php index 422250a6..5ab2808b 100644 --- a/ci4/app/Helpers/rbac_helper.php +++ b/ci4/app/Helpers/rbac_helper.php @@ -29,8 +29,12 @@ if (!function_exists('generate_php_roles_constant')) { // Close the array $phpCode .= "];\n"; - // Write PHP code to a file - $filePath = APPPATH . "Config/RBAC/roles.php"; + $dirPath = APPPATH . "Config/RBAC"; + if (!is_dir($dirPath)) { + mkdir($dirPath, 0775, true); // true permite crear carpetas anidadas + } + + $filePath = $dirPath . "/roles.php"; file_put_contents($filePath, $phpCode); } @@ -58,9 +62,14 @@ if (!function_exists('generate_php_permissions_constant')) { // Close the array $phpCode .= "];\n"; - // Write PHP code to a file - $filePath = APPPATH . "Config/RBAC/permissions.php"; + $dirPath = APPPATH . "Config/RBAC"; + if (!is_dir($dirPath)) { + mkdir($dirPath, 0775, true); // true permite crear carpetas anidadas + } + + $filePath = $dirPath . "/permissions.php"; file_put_contents($filePath, $phpCode); + } } @@ -87,8 +96,12 @@ if (!function_exists('generate_php_permissions_matrix_constant')) { // Close the array $phpCode .= "];\n"; - // Write PHP code to a file - $filePath = APPPATH . "Config/RBAC/permissionMatrix.php"; + $dirPath = APPPATH . "Config/RBAC"; + if (!is_dir($dirPath)) { + mkdir($dirPath, 0775, true); // true permite crear carpetas anidadas + } + + $filePath = $dirPath . "/permissionMatrix.php"; file_put_contents($filePath, $phpCode); } } @@ -130,9 +143,9 @@ if (!function_exists('checkGroups')) { */ function checkGroups(array $groups, string $redirectRoute = null) { - $session = \Config\Services::session(); + $session = \Config\Services::session(); $response = \Config\Services::response(); - $auth = auth(); // Shield auth service + $auth = auth(); // Shield auth service $user = $auth->user();