PHP code example of tleckie / acl

1. Go to this page and download the library: Download tleckie/acl 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/ */

    

tleckie / acl example snippets




= new Acl();

$acl->addRole('USER-0');
$acl->addRole('USER-1', ['USER-0']); // (USER-0) parent role.
$acl->addRole('USER-2', ['USER-1']); // (USER-1) parent role.

$acl->addResource('RESOURCE-0'); 
$acl->addResource('RESOURCE-1', ['RESOURCE-0']); // (RESOURCE-0) parent resource.
$acl->addResource('RESOURCE-2', ['RESOURCE-1']); // (RESOURCE-1) parent resource.
$acl->addResource('RESOURCE-3', ['RESOURCE-2']); // (RESOURCE-2) parent resource.

$acl->allow(['USER-0'], ['RESOURCE-0']);
$acl->deny(['USER-1'], ['RESOURCE-3'],['view','edit','list']);

$acl->isAllowed('USER-0','RESOURCE-2'); // true
$acl->isAllowed('USER-1','RESOURCE-3'); // true
$acl->isAllowed('USER-1','RESOURCE-3', 'view'); // false
$acl->isAllowed('USER-2','RESOURCE-3'); // true
$acl->isAllowed('USER-2','RESOURCE-3', 'view'); // false