https://github.com/alvan/acl
Another ACL (Access Control List)
https://github.com/alvan/acl
acl php
Last synced: 5 months ago
JSON representation
Another ACL (Access Control List)
- Host: GitHub
- URL: https://github.com/alvan/acl
- Owner: alvan
- License: mit
- Created: 2021-04-13T09:09:06.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2021-04-13T09:10:18.000Z (about 5 years ago)
- Last Synced: 2024-04-16T08:55:43.033Z (about 2 years ago)
- Topics: acl, php
- Language: PHP
- Homepage:
- Size: 2.93 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
About
-----
Another ACL (Access Control List).
Usage
-----
```php
$acl = new A\Acl;
$acl->setComparer(new A\Acl\Comparer\Location);
$acl->setDiscover(new class implements A\Acl\Discover
{
/**
* @param A\Acl $assembly
* @param mixed $accessor
* @return A\Acl\Instance|null
*/
public function discover(A\Acl $assembly, $accessor) : ?A\Acl\Instance
{
$instance = null;
if ($accessor)
{
$instance = $assembly->create();
// Set default roles...
$instance->extend('guest');
// Try to retrieve ACL rules from database or other sources by specified accessor ID...
// And then setup the acl instance...
// ...
}
return $instance;
}
});
$acl->create('admin')
->permit('.*')
;
$acl->create('guest')
->forbid('.*')
->handle('admin/guess', function() : ?int {
return date('n') % 2;
})
->permit('admin/login')
->permit('index')
;
// int(1)
var_dump($acl->access('admin', 'admin/posts'));
// int(0)
var_dump($acl->access('guest', 'admin/posts'));
// int(1) if the "month" value is an odd number
var_dump($acl->access('guest', 'admin/guess'));
// int(1)
var_dump($acl->access('guest', 'admin/login'));
// int(1)
var_dump($acl->access('other', 'index/posts'));
```