PHP code example of dancasdev / gac

1. Go to this page and download the library: Download dancasdev/gac library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

dancasdev / gac example snippets


use DancasDev\GAC\GAC;
use DancasDev\GAC\Schema;

// 1. Crear el esquema de tablas (se ejecuta UNA SOLA VEZ en la instalación o migración inicial)
Schema::install($pdo);

// 2. Instanciar GAC con la conexión a la base de datos
$gac = new GAC($pdo);

// 3. Declarar la entidad (usuario ID: 10) y el scope activo
$gac->setEntity('user', 10)
    ->setScope('/sucursal/caracas');

// 4. Evaluar la autorización para un módulo y acción
if ($gac->can('caja_chica', 'read')) {
    // El usuario 10 tiene permiso para leer caja_chica en /sucursal/caracas
}
bash
php test/TestRunner.php