@@ -9,71 +9,57 @@ class Geo extends Middleware
9
9
{
10
10
public function check ($ patterns )
11
11
{
12
- $ status = false ;
12
+ $ places = [ ' continents ' , ' regions ' , ' countries ' , ' cities ' ] ;
13
13
14
- if ($ this ->isEmpty ()) {
15
- return $ status ;
14
+ if ($ this ->isEmpty ($ places )) {
15
+ return false ;
16
16
}
17
17
18
18
if (!$ location = $ this ->getLocation ()) {
19
- return $ status ;
20
- }
21
-
22
- if ($ this ->isFiltered ($ location , 'continents ' )) {
23
- $ status = true ;
24
- }
25
-
26
- if (!$ status && $ this ->isFiltered ($ location , 'regions ' )) {
27
- $ status = true ;
19
+ return false ;
28
20
}
29
21
30
- if (!$ status && $ this ->isFiltered ($ location , 'countries ' )) {
31
- $ status = true ;
32
- }
22
+ foreach ($ places as $ place ) {
23
+ if (!$ this ->isFiltered ($ location , $ place )) {
24
+ continue ;
25
+ }
33
26
34
- if (!$ status && $ this ->isFiltered ($ location , 'cities ' )) {
35
- $ status = true ;
27
+ return true ;
36
28
}
37
29
38
- return $ status ;
30
+ return false ;
39
31
}
40
32
41
- protected function isEmpty ()
33
+ protected function isEmpty ($ places )
42
34
{
43
- $ status = true ;
44
-
45
- $ types = ['continents ' , 'regions ' , 'countries ' , 'cities ' ];
46
-
47
- foreach ($ types as $ type ) {
48
- if (!$ list = config ('firewall.middleware. ' . $ this ->middleware . '. ' . $ type )) {
35
+ foreach ($ places as $ place ) {
36
+ if (!$ list = config ('firewall.middleware. ' . $ this ->middleware . '. ' . $ place )) {
49
37
continue ;
50
38
}
51
39
52
40
if (empty ($ list ['allow ' ]) && empty ($ list ['block ' ])) {
53
41
continue ;
54
42
}
55
43
56
- $ status = false ;
57
-
58
- break ;
44
+ return false ;
59
45
}
60
46
61
- return $ status ;
47
+ return true ;
62
48
}
63
49
64
- protected function isFiltered ($ location , $ type )
50
+ protected function isFiltered ($ location , $ place )
65
51
{
66
- if (!$ list = config ('firewall.middleware. ' . $ this ->middleware . '. ' . $ type )) {
52
+ if (!$ list = config ('firewall.middleware. ' . $ this ->middleware . '. ' . $ place )) {
67
53
return false ;
68
54
}
69
55
70
- $ s_type = Str::singular ($ type );
56
+ $ s_place = Str::singular ($ place );
71
57
72
- if (!empty ($ list ['allow ' ]) && !in_array ((string ) $ location ->$ s_type , (array ) $ list ['allow ' ])) {
58
+ if (!empty ($ list ['allow ' ]) && !in_array ((string ) $ location ->$ s_place , (array ) $ list ['allow ' ])) {
73
59
return true ;
74
60
}
75
61
76
- if (in_array ((string ) $ location ->$ s_type , (array ) $ list ['block ' ])) {
62
+ if (in_array ((string ) $ location ->$ s_place , (array ) $ list ['block ' ])) {
77
63
return true ;
78
64
}
79
65
0 commit comments