Completed
Push — master ( ae3446...a9781c )
by Mahmoud
06:03
created

LaratrustRoleForWeb::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
1
<?php
2
3
namespace App\Containers\Authorization\Middlewares;
4
5
use App\Port\Foundation\Portals\PortButler;
6
use Closure;
7
use Illuminate\Contracts\Auth\Guard;
8
use Illuminate\Http\Request;
9
10
/**
11
 * Class LaratrustRoleForWeb
12
 *
13
 * @author  Mahmoud Zalt  <[email protected]>
14
 */
15
class LaratrustRoleForWeb
16
{
17
18
    /**
19
     * @var  \Illuminate\Contracts\Auth\Guard
20
     */
21
    protected $auth;
22
23
    /**
24
     * @var  \App\Port\Foundation\Portals\PortButler
25
     */
26
    private $portButler;
27
28
    /**
29
     * Creates a new instance of the middleware.
30
     *
31
     * @param Guard                               $auth
32
     * @param \App\Port\Foundation\Portals\PortButler $portButler
33
     */
34
    public function __construct(Guard $auth, PortButler $portButler)
35
    {
36
        $this->auth = $auth;
37
        $this->portButler = $portButler;
38
    }
39
40
    /**
41
     * Handle an incoming request.
42
     *
43
     * @param  \Illuminate\Http\Request $request
44
     * @param  Closure                  $next
45
     * @param                           $roles
46
     *
47
     * @return mixed
48
     */
49
    public function handle(Request $request, Closure $next, $roles)
50
    {
51
        if ($this->auth->guest() || !$request->user()->hasRole(explode('|', $roles))) {
52
            return view($this->portButler->getLoginWebPageName());
53
        }
54
55
        return $next($request);
56
    }
57
}
58