-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathACL.php
42 lines (36 loc) · 976 Bytes
/
ACL.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
/**
* A simple JSON based ACL class for PHP projects
* @author Sebatiaan Franken <[email protected]>
* @package ACL
*/
class ACL
{
/**
* @var stdClass $rules
*/
protected $rules;
public function __construct()
{
if(file_exists(ROOT . DS . 'acl.json'))
{
$this->rules = json_decode( file_get_contents( ROOT . DS . 'acl.json' ) );
}
else
{
trigger_error('The <em>acl.json</em> file could not be found in <em>' . ROOT . DS . '</em>', E_USER_ERROR);
}
}
public function can($role, $resource, $action)
{
return ($this->rules->$role->$resource->$action) ? true : false;
}
public function cannot($role, $resource, $action)
{
return !$this->can($role, $resource, $action);
}
public function test($role, $resource, $action)
{
return ('A <em>'. $role . '</em> <strong>' . ($this->can($role, $resource, $action) ? 'can' : 'cannot') . '</strong> <em>' . $action . '</em> a <em>' . $resource . '</em>') . PHP_EOL;
}
}