Overview
GAC uses adapters to interact with your database and cache systems. This design allows you to use the built-in adapters or create custom implementations for your specific infrastructure.Database Adapter
The database adapter handles all queries to retrieve permissions, restrictions, roles, and module data.Using Built-in Database Adapter
- With PDO Instance
- With Connection Array
- With Custom Adapter
If you already have a PDO connection, pass it directly:
Database Adapter Interface
The built-inDatabaseAdapter class (src/Adapters/DatabaseAdapter.php:9) implements these methods:
Example: Database Adapter Queries
Here’s how the built-in adapter retrieves roles (src/Adapters/DatabaseAdapter.php:49):
Cache Adapter
The cache adapter stores processed permissions and restrictions to improve performance. It significantly reduces database queries.Using Built-in Cache Adapter
- File-based Cache
- Custom Configuration
- With Custom Adapter
The default cache adapter stores data as JSON files:
Cache Adapter Interface
The built-inCacheAdapter class (src/Adapters/CacheAdapter.php:8) implements:
How Caching Works
When you callgetPermissions() or getRestrictions(), GAC:
- Generates a unique cache key based on entity type and ID
- Checks if cached data exists and is valid (not expired)
- If cache hit: returns cached data
- If cache miss: queries database, processes data, stores in cache, returns data
src/GAC.php:49):
- User #123 permissions:
gac_p_1_123 - Client #456 restrictions:
gac_r_2_456 - Global restrictions:
gac_r_global
Cache TTL Management
You can set different TTL values per entity:Complete Setup Example
Here’s a complete initialization with both adapters:Environment-based Configuration
- Development
- Production
- Testing
Dependency Injection
If you’re using a framework with DI, create a service:Error Handling
Database Connection Errors
Database Connection Errors
Cache Directory Errors
Cache Directory Errors
Invalid Adapter Implementation
Invalid Adapter Implementation
Verifying Setup
Test your adapter configuration:Next Steps
Checking Permissions
Learn how to check permissions in your application
Custom Adapters
Create custom database and cache adapters