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