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