PHP code example of szonov / dot-acl

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

    

szonov / dot-acl example snippets


$acl->allow('superadmin', '*.*');
$acl->allow('user', 'user.*');
$acl->allow('operator', '*.read');
$acl->allow('visitor', 'post.view');

$acl->allow('user', '!admin.*'); // is the same as $acl->deny('user', 'admin.*')
$acl->deny('admin', '!admin.*'); // is the same as $acl->allow('admin', 'admin.*')



use SZonov\DotAcl\Acl;

$acl = new Acl();

$acl->setDefaultAction(false);

$acl->addRole('guest');
$acl->addRole('user');

$acl->addRole('admin', 'user');

$acl->allow('guest', 'system.index');
$acl->allow('guest', 'public.*');
$acl->allow('user', 'auth.logout');
$acl->allow('admin', '*.*');

echo "-------------- ALL ROLES -------------- \n";
print_r($acl->getRoles());

echo "------ ALLOWED TO public.index -------- \n";
print_r($acl->getAllowedRoles('public.index'));

echo "\n------ guest::system.index -------- \n";
var_export($acl->isAllowed('guest','system.index'));

echo "\n------ user::system.index -------- \n";
var_export($acl->isAllowed('user','system.index'));
echo "\n";

// output:
// -------------- ALL ROLES --------------
// Array
// (
//    [0] => guest
//    [1] => user
//    [2] => admin
// )
// ------ ALLOWED TO public.index --------
// Array
// (
//    [0] => guest
//    [1] => admin
// )
//   
// ------ guest::system.index --------
// true
// ------ user::system.index --------
// false