PHPackages                             voku/simpleacl - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. voku/simpleacl

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

voku/simpleacl
==============

Simple Access Control List (ACL) for PHP.

7.0.0(8y ago)55.7k2[2 PRs](https://github.com/voku/SimpleAcl/pulls)BSD-3-ClausePHPPHP &gt;=7.0.0

Since Oct 28Pushed 1y ago2 watchersCompare

[ Source](https://github.com/voku/SimpleAcl)[ Packagist](https://packagist.org/packages/voku/simpleacl)[ Docs](https://github.com/alexshelkov/SimpleAcl)[ RSS](/packages/voku-simpleacl/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (46)Used By (0)

[![Build Status](https://camo.githubusercontent.com/7f9410b4fb367e6cdfa583d78a4ee09eedd9bccaae768b981ee650240d14041e/68747470733a2f2f7472617669732d63692e6f72672f766f6b752f53696d706c6541636c2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/voku/SimpleAcl)[![codecov.io](https://camo.githubusercontent.com/8ca11b880a356e49170fc60255bc3ddc19d1941f2d07436192e6d15c2d73d426/68747470733a2f2f636f6465636f762e696f2f6769746875622f766f6b752f53696d706c6541636c2f636f7665726167652e7376673f6272616e63683d6d6173746572)](https://codecov.io/github/voku/SimpleAcl?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/ad851a8893a68eef6cb09a9321664df7955f3e1f36ad372773d035d83ced79ac/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f766f6b752f53696d706c6541636c2f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/voku/SimpleAcl/?branch=master)[![Codacy Badge](https://camo.githubusercontent.com/9b9c61dbeebf56e200268334ce8bd5566b974d7c02119680f3a3912ac5433d01/68747470733a2f2f6170692e636f646163792e636f6d2f70726f6a6563742f62616467652f6434333664393931313038343438343638633838353463373766363261653063)](https://www.codacy.com/app/voku/SimpleAcl)[![SensioLabsInsight](https://camo.githubusercontent.com/a1405ad72e621f49227907a0f0854fcf7fec7654215a6357b4df29e9e0ccaf93/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f33643161373735652d303137622d346133352d393737362d3834363739333137653830372f6d696e692e706e67)](https://insight.sensiolabs.com/projects/3d1a775e-017b-4a35-9776-84679317e807)[![Latest Stable Version](https://camo.githubusercontent.com/1ca612c0d710204e3df6b7048108457538677814e30994dad006fe3eee03edb6/68747470733a2f2f706f7365722e707567782e6f72672f766f6b752f73696d706c6561636c2f762f737461626c65)](https://packagist.org/packages/voku/simpleacl)[![Total Downloads](https://camo.githubusercontent.com/4b1dc1be6b44ef1a78575f85032b845ac4242631d9858d06cad6b13aa6455852/68747470733a2f2f706f7365722e707567782e6f72672f766f6b752f73696d706c6561636c2f646f776e6c6f616473)](https://packagist.org/packages/voku/simpleacl)[![Latest Unstable Version](https://camo.githubusercontent.com/dd3d2b9b04f115af63073d6928c609269d2d697b6e775f6495f1283ae3460dc6/68747470733a2f2f706f7365722e707567782e6f72672f766f6b752f73696d706c6561636c2f762f756e737461626c65)](https://packagist.org/packages/voku/simpleacl)[![PHP 7 ready](https://camo.githubusercontent.com/f70ef9f52a44e0d8ccc53517c62afae159cfd41506760cfbe2c157bcfa7da055/687474703a2f2f7068703772656164792e74696d6573706c696e7465722e63682f766f6b752f53696d706c6541636c2f62616467652e737667)](https://travis-ci.org/voku/SimpleAcl)[![License](https://camo.githubusercontent.com/fff551999cac92eb6c4b3e9671725aa684d29d463d02bf8c711c4a98608cd3d8/68747470733a2f2f706f7365722e707567782e6f72672f766f6b752f73696d706c6561636c2f6c6963656e7365)](https://packagist.org/packages/voku/simpleacl)

Simple Access Control List (ACL) for PHP.
=========================================

[](#simple-access-control-list-acl-for-php)

WARNING: this is only a Maintained-Fork of ""

---

#### Install

[](#install)

##### Using composer

[](#using-composer)

Add following in your composer.json:

```
{
    "require": {
        "voku/simpleacl": "3.*"
    }
}
```

##### Manual

[](#manual)

Download library and register PSR-0 compatible autoloader.

---

#### Usage

[](#usage)

##### Basic usage

[](#basic-usage)

###### Theory

[](#theory)

There is 4 kind of objects: *Rules*, *Roles*, *Resources* and *Acl* which holds list of *Rules*. Some *Rule* can grant access for some *Role* to some *Resource*.

###### Create rules

[](#create-rules)

Lets create "View" Rule, and with with it grant access for "User" to "Page" (note: all names are case sensitive):

```
$view = new Rule('View');
$view->setRole(new Role('User'));
$view->setResource(new Resource('Page'));
$view->setAction(true); // true means that we allow access

var_dump((bool)$view->isAllowed('View', 'User', 'Page')); // true
```

###### Add rules

[](#add-rules)

There is not much sense in rules without Acl. So we need to add rules in it. In next example we add few rules in Acl and see whats happens.

```
$acl = new Acl();

$user = new Role('User');
$admin = new Role('Admin');

$siteFrontend = new Resource('SiteFrontend');
$siteBackend = new Resource('SiteBackend');

$acl->addRule($user, $siteFrontend, new Rule('View'), true);
$acl->addRule($admin, $siteFrontend, 'View', true); // you can use string as rule
$acl->addRule($admin, $siteBackend, 'View', true);

var_dump($acl->isAllowed('User', 'SiteFrontend', 'View')); // true
var_dump($acl->isAllowed('User', 'SiteBackend', 'View')); // false
var_dump($acl->isAllowed('Admin', 'SiteFrontend', 'View')); // true
var_dump($acl->isAllowed('Admin', 'SiteBackend', 'View')); // true
```

They are various way to add rules to *Acl*, addRule method accepts from one to four arguments, so you can also add rules like this:

```
