Total Complexity | 5 |
Total Lines | 46 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | <?php |
||
9 | class GuardChecker |
||
10 | { |
||
11 | /** |
||
12 | * Get guards passed as parameters to `auth` middleware. |
||
13 | * |
||
14 | * @param \Illuminate\Http\Request $request |
||
15 | * @return array |
||
16 | */ |
||
17 | 4 | public static function getAuthGuards(Request $request) |
|
18 | { |
||
19 | 4 | $middlewares = $request->route()->middleware(); |
|
20 | |||
21 | 4 | $guards = []; |
|
22 | 4 | foreach ($middlewares as $middleware) { |
|
23 | 4 | if (Str::startsWith($middleware, 'auth')) { |
|
24 | 3 | $explodedGuards = explode(',', Str::after($middleware, ':')); |
|
25 | 4 | $guards = array_unique(array_merge($guards, $explodedGuards)); |
|
26 | } |
||
27 | } |
||
28 | |||
29 | 4 | return $guards; |
|
30 | } |
||
31 | |||
32 | /** |
||
33 | * Get guards provider returning a assoc array with provider on key and |
||
34 | * guard on value. |
||
35 | * |
||
36 | * @param array $guards |
||
37 | * @return Collection |
||
38 | */ |
||
39 | 2 | public static function getGuardsProviders($guards) |
|
40 | { |
||
41 | return collect($guards)->mapWithKeys(function ($guard) { |
||
42 | 2 | return [self::defaultGuardProvider($guard) => $guard]; |
|
43 | 2 | }); |
|
44 | } |
||
45 | |||
46 | /** |
||
47 | * Get default provider from guard. |
||
48 | * |
||
49 | * @param string $guard |
||
50 | * @return string|null |
||
51 | */ |
||
52 | 3 | public static function defaultGuardProvider($guard) |
|
55 | } |
||
56 | } |
||
57 |