1
|
|
|
<?php namespace Anomaly\UsersModule\Http\Middleware; |
2
|
|
|
|
3
|
|
|
use Anomaly\UsersModule\User\UserSecurity; |
4
|
|
|
use Closure; |
5
|
|
|
use Illuminate\Contracts\Auth\Guard; |
6
|
|
|
use Illuminate\Http\Request; |
7
|
|
|
use Illuminate\Routing\Redirector; |
8
|
|
|
use Illuminate\Routing\ResponseFactory; |
9
|
|
|
use Symfony\Component\HttpFoundation\Response; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class CheckSecurityRequest |
13
|
|
|
* |
14
|
|
|
* This class replaces the Laravel version in app/ |
15
|
|
|
* |
16
|
|
|
* @link http://pyrocms.com/ |
17
|
|
|
* @author PyroCMS, Inc. <[email protected]> |
18
|
|
|
* @author Ryan Thompson <[email protected]> |
19
|
|
|
*/ |
20
|
|
|
class CheckSecurity |
21
|
|
|
{ |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* The Guard implementation. |
25
|
|
|
* |
26
|
|
|
* @var Guard |
27
|
|
|
*/ |
28
|
|
|
protected $guard; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* The security utility. |
32
|
|
|
* |
33
|
|
|
* @var UserSecurity |
34
|
|
|
*/ |
35
|
|
|
protected $security; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* The response factory. |
39
|
|
|
* |
40
|
|
|
* @var ResponseFactory |
41
|
|
|
*/ |
42
|
|
|
protected $response; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* The redirector utility. |
46
|
|
|
* |
47
|
|
|
* @var Redirector |
48
|
|
|
*/ |
49
|
|
|
protected $redirect; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Create a new CheckSecurityRequest instance. |
53
|
|
|
* |
54
|
|
|
* @param Guard $guard |
55
|
|
|
* @param Redirector $redirect |
56
|
|
|
* @param ResponseFactory $response |
57
|
|
|
* @param UserSecurity $security |
58
|
|
|
*/ |
59
|
|
|
public function __construct( |
60
|
|
|
Guard $guard, |
61
|
|
|
Redirector $redirect, |
62
|
|
|
ResponseFactory $response, |
63
|
|
|
UserSecurity $security |
64
|
|
|
) { |
65
|
|
|
$this->guard = $guard; |
66
|
|
|
$this->redirect = $redirect; |
67
|
|
|
$this->response = $response; |
68
|
|
|
$this->security = $security; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Handle an incoming request. |
73
|
|
|
* |
74
|
|
|
* @param \Illuminate\Http\Request $request |
75
|
|
|
* @param \Closure $next |
76
|
|
|
* @return mixed |
77
|
|
|
*/ |
78
|
|
|
public function handle(Request $request, Closure $next) |
79
|
|
|
{ |
80
|
|
|
$response = $this->security->check($this->guard->user()); |
81
|
|
|
|
82
|
|
|
if ($response instanceof Response) { |
|
|
|
|
83
|
|
|
return $response; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
return $next($request); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.json
file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.json
to be in the root folder of your repository.Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the
require
orrequire-dev
section?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceof
checks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.