1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Arcanedev\RouteViewer; |
6
|
|
|
|
7
|
|
|
use Arcanedev\RouteViewer\Contracts\RouteViewer as RouteViewerContract; |
8
|
|
|
use Illuminate\Contracts\Config\Repository as Config; |
9
|
|
|
use Illuminate\Contracts\Routing\Registrar as Router; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class RouteViewer |
13
|
|
|
* |
14
|
|
|
* @author ARCANEDEV <[email protected]> |
15
|
|
|
*/ |
16
|
|
|
class RouteViewer implements RouteViewerContract |
17
|
|
|
{ |
18
|
|
|
/* ----------------------------------------------------------------- |
19
|
|
|
| Properties |
20
|
|
|
| ----------------------------------------------------------------- |
21
|
|
|
*/ |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* The router instance. |
25
|
|
|
* |
26
|
|
|
* @var \Illuminate\Routing\Router |
27
|
|
|
*/ |
28
|
|
|
private $router; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* The config repository. |
32
|
|
|
* |
33
|
|
|
* @var \Illuminate\Contracts\Config\Repository |
34
|
|
|
*/ |
35
|
|
|
private $config; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* The route collection. |
39
|
|
|
* |
40
|
|
|
* @var \Arcanedev\RouteViewer\Entities\RouteCollection |
41
|
|
|
*/ |
42
|
|
|
protected $routes; |
43
|
|
|
|
44
|
|
|
/* ----------------------------------------------------------------- |
45
|
|
|
| Constructor |
46
|
|
|
| ----------------------------------------------------------------- |
47
|
|
|
*/ |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* RouteViewer constructor. |
51
|
|
|
* |
52
|
|
|
* @param \Illuminate\Contracts\Routing\Registrar $router |
53
|
|
|
* @param \Illuminate\Contracts\Config\Repository $config |
54
|
|
|
*/ |
55
|
12 |
|
public function __construct(Router $router, Config $config) |
56
|
|
|
{ |
57
|
12 |
|
$this->router = $router; |
|
|
|
|
58
|
12 |
|
$this->config = $config; |
59
|
12 |
|
} |
60
|
|
|
|
61
|
|
|
/* ----------------------------------------------------------------- |
62
|
|
|
| Main Methods |
63
|
|
|
| ----------------------------------------------------------------- |
64
|
|
|
*/ |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Get all routes. |
68
|
|
|
* |
69
|
|
|
* @return \Arcanedev\RouteViewer\Entities\RouteCollection |
70
|
|
|
*/ |
71
|
8 |
|
public function all() |
72
|
|
|
{ |
73
|
8 |
|
if (is_null($this->routes)) { |
74
|
8 |
|
$this->routes = Entities\RouteCollection::load( |
75
|
8 |
|
$this->router->getRoutes()->getRoutes(), |
76
|
8 |
|
$this->getExcludedUris(), |
77
|
8 |
|
$this->getExcludedMethods(), |
78
|
8 |
|
$this->getMethodColors() |
79
|
|
|
); |
80
|
|
|
} |
81
|
|
|
|
82
|
8 |
|
return $this->routes; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Get the excluded URIs. |
87
|
|
|
* |
88
|
|
|
* @return array |
89
|
|
|
*/ |
90
|
8 |
|
public function getExcludedUris(): array |
91
|
|
|
{ |
92
|
8 |
|
return $this->getConfig('uris.excluded', []); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Get the excluded methods. |
97
|
|
|
* |
98
|
|
|
* @return array |
99
|
|
|
*/ |
100
|
8 |
|
public function getExcludedMethods(): array |
101
|
|
|
{ |
102
|
8 |
|
return $this->getConfig('methods.excluded', ['HEAD']); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Get method colors. |
107
|
|
|
* |
108
|
|
|
* @return array |
109
|
|
|
*/ |
110
|
8 |
|
private function getMethodColors(): array |
111
|
|
|
{ |
112
|
8 |
|
return $this->getConfig('methods.colors', [ |
113
|
8 |
|
'GET' => 'success', |
114
|
|
|
'HEAD' => 'default', |
115
|
|
|
'POST' => 'primary', |
116
|
|
|
'PUT' => 'warning', |
117
|
|
|
'PATCH' => 'info', |
118
|
|
|
'DELETE' => 'danger', |
119
|
|
|
]); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/* ----------------------------------------------------------------- |
123
|
|
|
| Other Methods |
124
|
|
|
| ----------------------------------------------------------------- |
125
|
|
|
*/ |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Get a config value. |
129
|
|
|
* |
130
|
|
|
* @param string $key |
131
|
|
|
* @param mixed|null $default |
132
|
|
|
* |
133
|
|
|
* @return mixed |
134
|
|
|
*/ |
135
|
8 |
|
private function getConfig(string $key, $default = null) |
136
|
|
|
{ |
137
|
8 |
|
return $this->config->get("route-viewer.{$key}", $default); |
138
|
|
|
} |
139
|
|
|
} |
140
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.