Total Complexity | 6 |
Total Lines | 36 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
7 | trait Gate |
||
8 | { |
||
9 | public function thisGateShouldAllow($gate, ...$parameters) |
||
10 | { |
||
11 | $gate = $this->defineNewGate($gate); |
||
12 | |||
13 | return function (...$payload) use ($gate, $parameters) { |
||
14 | return GateFacade::allows($gate, (array_merge($parameters, ...$payload))); |
||
15 | }; |
||
16 | } |
||
17 | |||
18 | /** |
||
19 | * @param $gate |
||
20 | * |
||
21 | * @return string |
||
22 | */ |
||
23 | private function defineNewGate($gate): string |
||
24 | { |
||
25 | // Define a Gate for inline closures passed as gate |
||
26 | if (is_callable($gate)) { |
||
27 | $closure = $gate; |
||
28 | $gate = str_random(10); |
||
29 | GateFacade::define($gate, $closure); |
||
30 | } |
||
31 | |||
32 | // Define a Gate for "class@method" gates |
||
33 | if (is_string($gate) && str_contains($gate, '@')) { |
||
34 | GateFacade::define($gate, $gate); |
||
35 | } |
||
36 | |||
37 | return $gate; |
||
38 | } |
||
39 | |||
40 | public function youShouldHaveRole(string $role) |
||
43 | } |
||
44 | |||
45 | |||
46 | } |