1 | <?php |
||
9 | trait HasPermissions |
||
10 | { |
||
11 | /** |
||
12 | * Check if a user has a specific permission assigned to them. |
||
13 | * |
||
14 | * @param string $permission |
||
15 | * @return boolean |
||
16 | */ |
||
17 | public function hasPermission($permission) |
||
27 | |||
28 | /** |
||
29 | * Check if a user has any of the permissions assigned to them. |
||
30 | * |
||
31 | * @param array $permissions |
||
32 | * @return boolean |
||
33 | */ |
||
34 | public function hasAnyPermission($permissions) |
||
50 | |||
51 | /** |
||
52 | * Check if a user has has one of the roles assigned to them. |
||
53 | * |
||
54 | * @param string|array $roles |
||
55 | * @return boolean |
||
56 | */ |
||
57 | public function hasRole($roles) |
||
71 | |||
72 | /** |
||
73 | * Get the permissions assigned to the user. |
||
74 | */ |
||
75 | public function permissions() |
||
79 | |||
80 | /** |
||
81 | * Get the role assigned to the user. |
||
82 | */ |
||
83 | public function role() |
||
87 | } |
||
88 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: