Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
PolicyTrait | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
5 | |
100.00% |
1 / 1 |
can | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
5 |
1 | <?php |
2 | /** |
3 | * Pop PHP Framework (http://www.popphp.org/) |
4 | * |
5 | * @link https://github.com/popphp/popphp-framework |
6 | * @author Nick Sagona, III <dev@nolainteractive.com> |
7 | * @copyright Copyright (c) 2009-2024 NOLA Interactive, LLC. (http://www.nolainteractive.com) |
8 | * @license http://www.popphp.org/license New BSD License |
9 | */ |
10 | |
11 | /** |
12 | * @namespace |
13 | */ |
14 | namespace Pop\Acl\Policy; |
15 | |
16 | use Pop\Acl\AclResource; |
17 | |
18 | /** |
19 | * Policy trait |
20 | * |
21 | * @category Pop |
22 | * @package Pop\Acl |
23 | * @author Nick Sagona, III <dev@nolainteractive.com> |
24 | * @copyright Copyright (c) 2009-2024 NOLA Interactive, LLC. (http://www.nolainteractive.com) |
25 | * @license http://www.popphp.org/license New BSD License |
26 | * @version 4.0.0 |
27 | */ |
28 | trait PolicyTrait |
29 | { |
30 | |
31 | /** |
32 | * Evaluate policy |
33 | * |
34 | * @param string $method |
35 | * @param ?AclResource $resource |
36 | * @return bool|null |
37 | */ |
38 | public function can(string $method, ?AclResource $resource = null): bool|null |
39 | { |
40 | $result = null; |
41 | $methods = (str_contains($method, ',')) ? |
42 | array_map('trim', explode(',', $method)) : [$method]; |
43 | |
44 | foreach ($methods as $method) { |
45 | if (is_callable([$this, $method])) { |
46 | $result = $this->{$method}($this, $resource); |
47 | } |
48 | |
49 | if ($result === false) { |
50 | return false; |
51 | } |
52 | } |
53 | |
54 | return $result; |
55 | } |
56 | |
57 | } |