The GAC permissions system controls access to modules through a granular approach that supports both category-level and module-level permissions. Permissions can be assigned directly to entities (users/clients) or inherited from roles, with a priority system determining which permissions take precedence.
When a permission is assigned to a category (to_entity_type = '0'), it automatically grants access to all modules within that category. This provides a convenient way to grant broad access.
// Category permission processing (GAC.php:411-414)if ($permission['to_entity_type'] === '0') { // Get all modules in this category $result = $modulesBy['category'][$permission['to_entity_id']] ?? [];}
You can check if a permission includes specific features:
// Check single feature$permission = $gac->getPermissions()->get('users');if ($permission->hasFeature('create')) { // User can create}// Check multiple featuresif ($permission->hasFeature(['read', 'update'])) { // User can read AND update}
The hasFeature() method implementation:
// Feature validation (Permission.php:54-72)public function hasFeature(string|array $feature) : bool { if (empty($this->feature) || !is_array($this->feature)) { return false; } $feature = is_array($feature) ? $feature : [$feature]; foreach ($feature as $value) { // Convert string to key if needed $value = $this->featureKeys[$value] ?? $value; if (!in_array($value, $this->feature)) { return false; } } return true;}
Permissions are loaded from the database and cached for performance:
// Set entity and load permissions$gac->setEntity('user', $userId);$permissions = $gac->getPermissions(); // Loads from cache if available// Force reload from database$permissions = $gac->getPermissions(false);
// 1. Initialize GAC$gac = new GAC();$gac->setDatabase($pdoConnection);$gac->setCache('my_app', 3600);// 2. Set the entity$gac->setEntity('user', 123);// 3. Load permissions$permissions = $gac->getPermissions();// 4. Check accessif ($permissions->has('users')) { $permission = $permissions->get('users'); // Check specific features if ($permission->hasFeature(['read', 'update'])) { // User can view and edit users echo "Access Level: " . $permission->getLevel(); } // Check development mode if ($permission->moduleIsDeveloping() && !$permission->hasFeature('dev')) { // Block access to developing modules throw new Exception('Module under development'); }} else { // No access to users module throw new Exception('Access denied');}