Conditions | 4 |
Paths | 3 |
Total Lines | 24 |
Code Lines | 10 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
21 | public function validatePermission() |
||
22 | { |
||
23 | // $this->access is optionally set on the Request |
||
24 | |||
25 | // allow access when the access is not defined |
||
26 | // allow access when nothing no roles or permissions are declared |
||
27 | if (!isset($this->access) || !isset($this->access['permission'])) { |
||
|
|||
28 | return true; |
||
29 | } |
||
30 | |||
31 | // allow access if has permission set but is empty or null |
||
32 | if(!$this->access['permission']){ |
||
33 | return true; |
||
34 | } |
||
35 | |||
36 | $permissions = explode('|', $this->access['permission']); |
||
37 | |||
38 | $hasPermission = array_map(function($permission) { |
||
39 | return $this->user()->hasPermissionTo($permission); |
||
40 | }, $permissions); |
||
41 | |||
42 | // allow access if user has access to any of the defined permissions. |
||
43 | return in_array(true, $hasPermission); |
||
44 | } |
||
45 | |||
47 |
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: