1 | <?php |
||
16 | class Permission { |
||
|
|||
17 | |||
18 | /** |
||
19 | * allowed permissions for actions on specific resources |
||
20 | * |
||
21 | * $perms[] = [ |
||
22 | * 'role' => 'student', //AROs |
||
23 | * 'resource' => 'Post' //ACOs - actions could be ACOs instead. |
||
24 | * 'actions' => ['edit', 'delete'], |
||
25 | * 'conditions' => ['owner'] - things that you validate against if the user has access to the action |
||
26 | * ]; |
||
27 | * |
||
28 | * @var array |
||
29 | */ |
||
30 | public static $perms = []; |
||
31 | |||
32 | /** |
||
33 | * check if the $role has access to $action on $resource |
||
34 | * |
||
35 | * @param string $role |
||
36 | * @param string $resource |
||
37 | * @param string $action if set to "*", then check if $actions parameter was assigned to "*" when using allow() method |
||
38 | * This indicates the $role has access to all actions on $resource |
||
39 | * @param array $config configuration data to be passed to condition methods |
||
40 | * @throws Exception if $config is empty or method doesn't exists |
||
41 | * @return boolean |
||
42 | */ |
||
43 | public static function check($role, $resource, $action = "*", array $config = []){ |
||
77 | |||
78 | /** |
||
79 | * Add new rule: allow a $role for $actions on $resource, |
||
80 | * You may add additional $conditions that must be fulfilled as well. |
||
81 | * |
||
82 | * @param string $role |
||
83 | * @param string $resource |
||
84 | * @param mixed $actions |
||
85 | * @param mixed $conditions |
||
86 | */ |
||
87 | public static function allow($role, $resource, $actions = "*", $conditions = []){ |
||
93 | |||
94 | /** |
||
95 | * deny or remove $actions for a $role on $resource |
||
96 | * |
||
97 | * @param string $role |
||
98 | * @param string $resource |
||
99 | * @param mixed $actions |
||
100 | */ |
||
101 | public static function deny($role, $resource, $actions = "*"){ |
||
119 | |||
120 | /** *********************************************** **/ |
||
121 | /** ************** Conditions ************** **/ |
||
122 | /** *********************************************** **/ |
||
123 | |||
124 | /** |
||
125 | * checks if user is owner |
||
126 | * |
||
127 | * @param array $config |
||
128 | * @return bool |
||
129 | */ |
||
130 | private static function owner($config){ |
||
141 | |||
142 | } |
||
143 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.