|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Bmatovu\RouteList\Controllers; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Routing\Controller; |
|
6
|
|
|
use Illuminate\Support\Facades\Route; |
|
7
|
|
|
|
|
8
|
|
|
class RouteListController extends Controller |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* Render routes. |
|
12
|
|
|
* |
|
13
|
|
|
* @return \Illuminate\Http\Response |
|
14
|
|
|
*/ |
|
15
|
1 |
|
public function __invoke() |
|
16
|
|
|
{ |
|
17
|
1 |
|
$routes = collect(Route::getRoutes()) |
|
18
|
1 |
|
->filter(function ($route) { |
|
19
|
1 |
|
return ! $this->matches(config('route-list.excluded'), $route->uri); |
|
20
|
1 |
|
})->map(function ($route) { |
|
21
|
|
|
return [ |
|
22
|
|
|
// 'host' => $route->action['where'], |
|
23
|
1 |
|
'uri' => $route->uri, |
|
24
|
1 |
|
'name' => $route->action['as'] ?? '', |
|
25
|
1 |
|
'methods' => $route->methods, |
|
26
|
1 |
|
'action' => $route->action['controller'] ?? 'Closure', |
|
27
|
1 |
|
'middleware' => $this->getRouteMiddleware($route), |
|
28
|
|
|
]; |
|
29
|
1 |
|
}); |
|
30
|
|
|
|
|
31
|
1 |
|
return view('route-list::index', [ |
|
32
|
1 |
|
'routes' => $routes, |
|
33
|
|
|
]); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Get route middleware. |
|
38
|
|
|
* |
|
39
|
|
|
* @param \Illuminate\Routing\Route $route |
|
40
|
|
|
* |
|
41
|
|
|
* @return string |
|
42
|
|
|
*/ |
|
43
|
1 |
|
protected function getRouteMiddleware($route) |
|
44
|
|
|
{ |
|
45
|
1 |
|
return collect($route->gatherMiddleware())->map(function ($middleware) { |
|
46
|
|
|
return $middleware instanceof Closure ? 'Closure' : $middleware; |
|
|
|
|
|
|
47
|
1 |
|
})->implode(', '); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Perform a regular expression match. |
|
52
|
|
|
* |
|
53
|
|
|
* @param array $patterns |
|
54
|
|
|
* @param string $subject |
|
55
|
|
|
* |
|
56
|
|
|
* @return bool |
|
57
|
|
|
*/ |
|
58
|
1 |
|
protected function matches($patterns, $subject) |
|
59
|
|
|
{ |
|
60
|
1 |
|
$isMatched = false; |
|
61
|
|
|
|
|
62
|
1 |
|
foreach ($patterns as $pattern) { |
|
63
|
1 |
|
if (preg_match($pattern, $subject)) { |
|
64
|
|
|
$isMatched = true; |
|
65
|
|
|
|
|
66
|
|
|
break; |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
1 |
|
return $isMatched; |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.jsonfile (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.jsonto 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
requireorrequire-devsection?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceofchecks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.