Completed
Push — master ( c53116...d0984d )
by Jeremy
07:52
created

VerifyPermission::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace jeremykenedy\LaravelRoles\App\Http\Middleware;
4
5
use Closure;
6
use Illuminate\Contracts\Auth\Guard;
7
use Illuminate\Http\Request;
8
use jeremykenedy\LaravelRoles\App\Exceptions\PermissionDeniedException;
9
10
class VerifyPermission
11
{
12
    /**
13
     * @var Guard
14
     */
15
    protected $auth;
16
17
    /**
18
     * Create a new filter instance.
19
     *
20
     * @param Guard $auth
21
     */
22
    public function __construct(Guard $auth)
23
    {
24
        $this->auth = $auth;
25
    }
26
27
    /**
28
     * Handle an incoming request.
29
     *
30
     * @param Request    $request
31
     * @param \Closure   $next
32
     * @param int|string $permission
33
     *
34
     * @throws \jeremykenedy\LaravelRoles\App\Exceptions\PermissionDeniedException
35
     *
36
     * @return mixed
37
     */
38
    public function handle($request, Closure $next, $permission)
39
    {
40
        if ($this->auth->check() && $this->auth->user()->hasPermission($permission)) {
41
            return $next($request);
42
        }
43
44
        throw new PermissionDeniedException($permission);
45
    }
46
}
47