40
40
class Router
41
41
{
42
42
/** Router Version */
43
- const VERSION = '2.5.2 ' ;
43
+ const VERSION = '3.0.0 ' ;
44
44
45
45
/** @var string $baseFolder Base folder of the project */
46
- protected $ baseFolder ;
46
+ protected string $ baseFolder ;
47
47
48
48
/** @var array $routes Routes list */
49
- protected $ routes = [];
49
+ protected array $ routes = [];
50
50
51
51
/** @var array $groups List of group routes */
52
- protected $ groups = [];
52
+ protected array $ groups = [];
53
53
54
54
/** @var array $patterns Pattern definitions for parameters of Route */
55
- protected $ patterns = [
55
+ protected array $ patterns = [
56
56
':all ' => '(.*) ' ,
57
57
':any ' => '([^/]+) ' ,
58
58
':id ' => '(\d+) ' ,
@@ -67,46 +67,46 @@ class Router
67
67
];
68
68
69
69
/** @var array $namespaces Namespaces of Controllers and Middlewares files */
70
- protected $ namespaces = [
70
+ protected array $ namespaces = [
71
71
'middlewares ' => '' ,
72
72
'controllers ' => '' ,
73
73
];
74
74
75
75
/** @var array $path Paths of Controllers and Middlewares files */
76
- protected $ paths = [
76
+ protected array $ paths = [
77
77
'controllers ' => 'Controllers ' ,
78
78
'middlewares ' => 'Middlewares ' ,
79
79
];
80
80
81
81
/** @var string $mainMethod Main method for controller */
82
- protected $ mainMethod = 'main ' ;
82
+ protected string $ mainMethod = 'main ' ;
83
83
84
84
/** @var string $cacheFile Cache file */
85
- protected $ cacheFile = '' ;
85
+ protected string $ cacheFile = '' ;
86
86
87
87
/** @var bool $cacheLoaded Cache is loaded? */
88
- protected $ cacheLoaded = false ;
88
+ protected bool $ cacheLoaded = false ;
89
89
90
90
/** @var Closure $errorCallback Route error callback function */
91
- protected $ errorCallback ;
91
+ protected Closure $ errorCallback ;
92
92
93
93
/** @var Closure $notFoundCallback Route exception callback function */
94
- protected $ notFoundCallback ;
94
+ protected Closure $ notFoundCallback ;
95
95
96
96
/** @var array $middlewares General middlewares for per request */
97
- protected $ middlewares = [];
97
+ protected array $ middlewares = [];
98
98
99
99
/** @var array $routeMiddlewares Route middlewares */
100
- protected $ routeMiddlewares = [];
100
+ protected array $ routeMiddlewares = [];
101
101
102
102
/** @var array $middlewareGroups Middleware Groups */
103
- protected $ middlewareGroups = [];
103
+ protected array $ middlewareGroups = [];
104
104
105
105
/** @var RouterRequest */
106
- private $ request ;
106
+ private RouterRequest $ request ;
107
107
108
108
/** @var bool */
109
- private $ debug = false ;
109
+ private bool $ debug = false ;
110
110
111
111
/**
112
112
* Router constructor method.
@@ -170,7 +170,7 @@ public function __call($method, $params)
170
170
171
171
[$ route , $ callback ] = $ params ;
172
172
$ options = $ params [2 ] ?? null ;
173
- if (strstr ($ route , ': ' )) {
173
+ if (str_contains ($ route , ': ' )) {
174
174
$ route1 = $ route2 = '' ;
175
175
foreach (explode ('/ ' , $ route ) as $ key => $ value ) {
176
176
if ($ value != '' ) {
@@ -228,13 +228,13 @@ public function add(string $methods, string $route, $callback, array $options =
228
228
/**
229
229
* Add new route rules pattern; String or Array
230
230
*
231
- * @param string| array $pattern
231
+ * @param array|string $pattern
232
232
* @param string|null $attr
233
233
*
234
234
* @return mixed
235
235
* @throws
236
236
*/
237
- public function pattern ($ pattern , string $ attr = null )
237
+ public function pattern (array | string $ pattern , string $ attr = null )
238
238
{
239
239
if (is_array ($ pattern )) {
240
240
foreach ($ pattern as $ key => $ value ) {
@@ -381,7 +381,7 @@ public function controller(string $route, string $controller, array $options = [
381
381
$ classMethods = get_class_methods ($ controller );
382
382
if ($ classMethods ) {
383
383
foreach ($ classMethods as $ methodName ) {
384
- if (!strstr ($ methodName , '__ ' )) {
384
+ if (!str_contains ($ methodName , '__ ' )) {
385
385
$ method = 'any ' ;
386
386
foreach (explode ('| ' , $ this ->request ->validMethods ()) as $ m ) {
387
387
if (stripos ($ methodName , $ m = strtolower ($ m ), 0 ) === 0 ) {
@@ -741,11 +741,11 @@ protected function addRoute(string $uri, string $method, $callback, ?array $opti
741
741
}
742
742
743
743
/**
744
- * @param array|string $middleware
744
+ * @param array|string|null $middleware
745
745
*
746
746
* @return array
747
747
*/
748
- protected function calculateMiddleware ($ middleware ): array
748
+ protected function calculateMiddleware (array | string | null $ middleware ): array
749
749
{
750
750
if (is_null ($ middleware )) {
751
751
return [];
@@ -761,6 +761,7 @@ protected function calculateMiddleware($middleware): array
761
761
* @param array $params
762
762
*
763
763
* @return void
764
+ * @throws Exception
764
765
*/
765
766
protected function runRouteCommand ($ command , array $ params = []): void
766
767
{
0 commit comments