PHP code example of innmind / acl

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

    

innmind / acl example snippets


use Innmind\ACL\{
    ACL,
    User,
    Group,
    Mode,
};

$acl = ACL::of('r---w---x user:group');

$acl->allows(User::of('foo'), Group::of('bar'), Mode::read); // false
$acl->allows(User::of('foo'), Group::of('bar'), Mode::write); // false
$acl->allows(User::of('foo'), Group::of('bar'), Mode::execute); // true
$acl->allows(User::of('foo'), Group::of('group'), Mode::read); // false
$acl->allows(User::of('foo'), Group::of('group'), Mode::write); // true
$acl->allows(User::of('foo'), Group::of('group'), Mode::execute); // true
$acl->allows(User::of('user'), Group::of('bar'), Mode::read); // true
$acl->allows(User::of('user'), Group::of('bar'), Mode::write); // false
$acl->allows(User::of('user'), Group::of('bar'), Mode::execute); // true
$acl->allows(User::of('user'), Group::of('group'), Mode::read); // true
$acl->allows(User::of('user'), Group::of('group'), Mode::write); // true
$acl->allows(User::of('user'), Group::of('group'), Mode::execute); // true
$acl->toString(); // outputs "r---w---x user:group"

$otherAcl = $acl->addUser(Mode::write);
$acl->toString(); // outputs "r---w---x user:group"
$otherAcl->toString(); // outputs "rw--w---x user:group"