PHP code example of matijabelec / acl-php

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

    

matijabelec / acl-php example snippets


    use MatijaBelec\Acl\Acl;
    $acl = new Acl();

    // create role hierarchy
    $acl->addRole('guest');
    $acl->addRole('user', 'guest');
    $acl->addRole('administrator', 'user');

    // create actions tree
    $acl->allow('guest', 'user.canUpdate');
    $acl->allow('guest', 'user.canDelete');
    $acl->allow('user', 'user.canCreate');
    $acl->deny('user', 'user.canDelete');
    $acl->allow('administrator', ['user.canRead', 'user.canUpdate']);
    $acl->allow('administrator', 'user.canDelete');

    // check actions on user
    $adminIsAllowedToGetUserDetails = $acl->isAllowed('administrator', 'user.canRead');
    $userIsAllowedToCreateNewUser = $acl->isAllowed('user', 'user.canCreate');