Completed
Push — develop ( cbad9d...de1065 )
by Abdelrahman
13:09
created

AbstractController::getGuard()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cortex\Foundation\Http\Controllers;
6
7
use Illuminate\Routing\Controller;
8
use Illuminate\Support\Facades\Route;
9
use Illuminate\Foundation\Bus\DispatchesJobs;
10
use Illuminate\Foundation\Validation\ValidatesRequests;
11
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
12
13
abstract class AbstractController extends Controller
14
{
15
    use DispatchesJobs;
16
    use ValidatesRequests;
17
    use AuthorizesRequests;
18
19
    /**
20
     * The authentication guard.
21
     *
22
     * @var string
23
     */
24
    protected $guard;
25
26
    /**
27
     * The broker name.
28
     *
29
     * @var string
30
     */
31
    protected $broker;
32
33
    /**
34
     * Whitelisted methods.
35
     * Array of whitelisted methods which do not need to go through middleware.
36
     *
37
     * @var array
38
     */
39
    protected $middlewareWhitelist = [];
40
41
    /**
42
     * Create a new authenticated controller instance.
43
     */
44
    public function __construct()
45
    {
46
        // Set accessarea to the global request parameter bag
47
        $accessArea = str_before(Route::currentRouteName(), '.');
48
        request()->request->add(['accessarea' => $accessArea]);
49
    }
50
51
    /**
52
     * Get the broker to be used.
53
     *
54
     * @return string
55
     */
56
    protected function getBroker(): string
57
    {
58
        return $this->broker;
59
    }
60
    /**
61
     * Get the guard to be used during authentication.
62
     *
63
     * @return string|null
64
     */
65
    protected function getGuard(): ?string
66
    {
67
        return $this->guard;
68
    }
69
70
    /**
71
     * Get the guest middleware for the application.
72
     */
73
    protected function getGuestMiddleware()
74
    {
75
        return ($guard = $this->getGuard()) ? 'guest:'.$guard : 'guest';
76
    }
77
78
    /**
79
     * Get the auth middleware for the application.
80
     *
81
     * @return string
82
     */
83
    protected function getAuthMiddleware(): string
84
    {
85
        return ($guard = $this->getGuard()) ? 'auth:'.$guard : 'auth';
86
    }
87
}
88