1 | <?php |
||
2 | declare(strict_types=1); |
||
3 | |||
4 | namespace Nexendrie\Menu; |
||
5 | |||
6 | /** |
||
7 | * ConditionCallback |
||
8 | * |
||
9 | * @author Jakub Konečný |
||
10 | */ |
||
11 | 1 | final class ConditionCallback extends BaseCondition { |
|
12 | /** |
||
13 | * @param callable $parameter |
||
14 | * @throws \InvalidArgumentException |
||
15 | * @throws \UnexpectedValueException |
||
16 | */ |
||
17 | public function isAllowed($parameter = null): bool { |
||
18 | 1 | if(!is_callable($parameter)) { |
|
19 | 1 | throw new \InvalidArgumentException("Method " . __METHOD__ . " expects callback as parameter."); |
|
20 | } |
||
21 | 1 | $result = call_user_func($parameter); |
|
22 | 1 | if(!is_bool($result)) { |
|
23 | 1 | throw new \UnexpectedValueException("The callback for method " . __METHOD__ . " has to return boolean, " . gettype($result) . " returned."); |
|
0 ignored issues
–
show
introduced
by
![]() |
|||
24 | } |
||
25 | 1 | return $result; |
|
26 | } |
||
27 | } |
||
28 | ?> |