Overview
TheGAC class is the core entry point for the Granular Access Control library. It manages database and cache adapters, entity configuration, and provides methods to retrieve permissions and restrictions.
Constructor
The GAC class uses a fluent interface pattern for configuration. Initialize without parameters and chain configuration methods.Configuration Methods
setDatabase()
Establishes database connection for GAC.Database connection parameters. Can be:
PDOinstance for direct PDO connectionarraywith connection parameters (passed to DatabaseAdapter)- Custom adapter implementing
DatabaseAdapterInterface
Returns the GAC instance for method chaining
DatabaseAdapterException if invalid adapter provided
setCache()
Configures caching for permissions and restrictions.Cache key prefix for stored data
Time to live in seconds (default: 30 minutes)
Cache directory path or custom adapter implementing
CacheAdapterInterfaceReturns the GAC instance for method chaining
CacheAdapterException if invalid adapter provided
setEntity()
Sets the entity (user or client) for permission/restriction queries.Entity type:
'user', 'client', or numeric type key ('1', '2')Unique identifier for the entity
Returns the GAC instance for method chaining
setCacheTtl()
Sets the cache time-to-live value.Cache lifetime in seconds
Returns the GAC instance for method chaining
setCacheKey()
Sets the cache key prefix.Prefix for all cache keys
Returns the GAC instance for method chaining
Data Retrieval Methods
getPermissions()
Retrieves permissions for the configured entity.Whether to attempt loading from cache before querying database
Permissions instance containing all module access permissions
Exception if entity type and ID not set
getRestrictions()
Retrieves restrictions for the configured entity.Whether to attempt loading from cache before querying database
Restrictions instance containing all active restrictions
Exception if entity type and ID not set
Cache Management Methods
clearCache()
Clears cached permissions and restrictions for the current entity.Whether to also clear global restrictions cache
Returns
true on success, false on failureCacheAdapterException if cache adapter not set
purgePermissionsBy()
Purges permissions cache by entity criteria.Entity type:
'user', 'client', 'role', or 'global'Array of entity IDs to purge. Required unless
entityType is 'global'Returns
true on success, false if no IDs provided for non-global purgepurgeRestrictionsBy()
Purges restrictions cache by entity criteria.Entity type:
'user', 'client', 'role', or 'global'Array of entity IDs to purge. Required unless
entityType is 'global'Returns
true on success, false if no IDs provided for non-global purgeGetter Methods
getEntityType()
Returns the configured entity type.The entity type key (
'1' for user, '2' for client)getEntityId()
Returns the configured entity ID.The entity identifier
getCacheKey()
Generates cache key for a given type.Type of cache:
'permissions', 'restrictions', or 'restrictions_global'Generated cache key
getEntityRoleData()
Retrieves role data for the current entity.Force reload from database
Array with
'list' (role IDs) and 'priority' (role priorities) keysComplete Usage Example
Public Properties
The configured database adapter instance
The configured cache adapter instance
See Also
- Permissions - Working with permission collections
- Permission - Individual permission details
- Restrictions - Working with restriction collections
- Restriction - Base restriction class