Skip to content

⚡ Tleckie\Acl component provides a lightweight and flexible access control list (ACL) implementation for privileges management.

License

Notifications You must be signed in to change notification settings

teodoroleckie/acl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

May 13, 2021
d2d1a24 · May 13, 2021

History

14 Commits
May 11, 2021
May 4, 2021
May 4, 2021
May 4, 2021
May 4, 2021
Apr 30, 2021
May 4, 2021
May 13, 2021
May 4, 2021
May 4, 2021
May 4, 2021

Repository files navigation

Tleckie\Acl access control list (ACL)

Tleckie\Acl component provides a lightweight and flexible access control list (ACL) implementation for privileges management. In general, an application may utilize such ACL‘s to control access to certain protected objects by other requesting objects.

Latest Version on Packagist Scrutinizer Code Quality Code Intelligence Status Build Status

Installation

You can install the package via composer:

composer require tleckie/acl

Usage

<?php

include_once "vendor/autoload.php";

$acl = 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