1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
if (! function_exists('is_excluded_route')) { |
4
|
|
|
function is_excluded_route($route) |
5
|
|
|
{ |
6
|
|
|
$namespaces = array_map('valid_namespace', config('menu.exclude.namespaces')); |
7
|
|
|
if (count($namespaces) > 0 |
8
|
|
|
&& preg_match("/^(" . implode('|', |
9
|
|
|
$namespaces) . ")(.*)/", trim($route->getActionName())) > 0) { |
10
|
|
|
return true; |
11
|
|
|
} |
12
|
|
|
|
13
|
|
|
$controllers = array_map('valid_namespace', config('menu.exclude.controllers')); |
14
|
|
|
if (count($controllers) > 0 |
15
|
|
|
&& preg_match("/^(" . implode('|', $controllers) . ")@(.*)/", trim($route->getActionName())) > 0) { |
16
|
|
|
return true; |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
$actions = array_map('valid_namespace', config('menu.exclude.actions')); |
20
|
|
|
if (count($actions) > 0 |
21
|
|
|
&& preg_match("/^(" . implode('|', $actions) . ")/", trim($route->getActionName())) > 0) { |
22
|
|
|
return true; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
return false; |
26
|
|
|
} |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
if (! function_exists('is_public_route')) { |
30
|
|
|
function is_public_route($route) |
31
|
|
|
{ |
32
|
|
|
$route = explode_route($route); |
33
|
|
|
$permissions = \PhpCollective\MenuMaker\Storage\Permission::publicRoutes(); |
34
|
|
|
return $permissions->where('namespace', $route['namespace']) |
35
|
|
|
->where('controller', $route['controller']) |
36
|
|
|
->where('method', $route['method']) |
37
|
|
|
->where('action', $route['action']) |
38
|
|
|
->count(); |
39
|
|
|
} |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
if (! function_exists('is_working_route')) { |
43
|
|
|
function is_working_route($route) |
44
|
|
|
{ |
45
|
|
|
$namespaces = array_map('valid_namespace', config('menu.include.namespaces')); |
46
|
|
|
if (count($namespaces) > 0 |
47
|
|
|
&& preg_match("/^(" . implode('|', |
48
|
|
|
$namespaces) . ")(.*)/", trim($route->getActionName())) > 0) { |
49
|
|
|
return true; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
$controllers = array_map('valid_namespace', config('menu.include.controllers')); |
53
|
|
|
if (count($controllers) > 0 |
54
|
|
|
&& preg_match("/^(" . implode('|', $controllers) . ")@(.*)/", trim($route->getActionName())) > 0) { |
55
|
|
|
return true; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
$actions = array_map('valid_namespace', config('menu.include.actions')); |
59
|
|
|
if (count($actions) > 0 |
60
|
|
|
&& preg_match("/^(" . implode('|', $actions) . ")/", |
61
|
|
|
trim($route->getActionName())) > 0) { |
62
|
|
|
return true; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
return false; |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
if (! function_exists('explode_route')) { |
70
|
|
|
function explode_route($route) |
71
|
|
|
{ |
72
|
|
|
$actionName = $route->getActionName(); |
73
|
|
|
$action = substr($actionName, strpos($actionName, '@') + 1); |
74
|
|
|
$controller = substr($actionName, strrpos($actionName, '\\') + 1, -(strlen($action) + 1)); |
75
|
|
|
return [ |
76
|
|
|
'namespace' => substr($actionName, 0, strrpos($actionName, '\\')), |
77
|
|
|
'controller' => $controller, |
78
|
|
|
'method' => $route->methods[0], |
79
|
|
|
'action' => $action |
80
|
|
|
]; |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
if (! function_exists('valid_namespace')) { |
85
|
|
|
function valid_namespace($namespace) |
86
|
|
|
{ |
87
|
|
|
return str_replace('\\', '\\\\', $namespace); |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
if (! function_exists('unauthorized')) { |
92
|
|
|
function unauthorized() |
93
|
|
|
{ |
94
|
|
|
return response()->view('menu-maker::errors.401'); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|