4040class Router
4141{
4242 /** Router Version */
43- const VERSION = '2.5.2 ' ;
43+ const VERSION = '3.0.0 ' ;
4444
4545 /** @var string $baseFolder Base folder of the project */
46- protected $ baseFolder ;
46+ protected string $ baseFolder ;
4747
4848 /** @var array $routes Routes list */
49- protected $ routes = [];
49+ protected array $ routes = [];
5050
5151 /** @var array $groups List of group routes */
52- protected $ groups = [];
52+ protected array $ groups = [];
5353
5454 /** @var array $patterns Pattern definitions for parameters of Route */
55- protected $ patterns = [
55+ protected array $ patterns = [
5656 ':all ' => '(.*) ' ,
5757 ':any ' => '([^/]+) ' ,
5858 ':id ' => '(\d+) ' ,
@@ -67,46 +67,46 @@ class Router
6767 ];
6868
6969 /** @var array $namespaces Namespaces of Controllers and Middlewares files */
70- protected $ namespaces = [
70+ protected array $ namespaces = [
7171 'middlewares ' => '' ,
7272 'controllers ' => '' ,
7373 ];
7474
7575 /** @var array $path Paths of Controllers and Middlewares files */
76- protected $ paths = [
76+ protected array $ paths = [
7777 'controllers ' => 'Controllers ' ,
7878 'middlewares ' => 'Middlewares ' ,
7979 ];
8080
8181 /** @var string $mainMethod Main method for controller */
82- protected $ mainMethod = 'main ' ;
82+ protected string $ mainMethod = 'main ' ;
8383
8484 /** @var string $cacheFile Cache file */
85- protected $ cacheFile = '' ;
85+ protected string $ cacheFile = '' ;
8686
8787 /** @var bool $cacheLoaded Cache is loaded? */
88- protected $ cacheLoaded = false ;
88+ protected bool $ cacheLoaded = false ;
8989
9090 /** @var Closure $errorCallback Route error callback function */
91- protected $ errorCallback ;
91+ protected Closure $ errorCallback ;
9292
9393 /** @var Closure $notFoundCallback Route exception callback function */
94- protected $ notFoundCallback ;
94+ protected Closure $ notFoundCallback ;
9595
9696 /** @var array $middlewares General middlewares for per request */
97- protected $ middlewares = [];
97+ protected array $ middlewares = [];
9898
9999 /** @var array $routeMiddlewares Route middlewares */
100- protected $ routeMiddlewares = [];
100+ protected array $ routeMiddlewares = [];
101101
102102 /** @var array $middlewareGroups Middleware Groups */
103- protected $ middlewareGroups = [];
103+ protected array $ middlewareGroups = [];
104104
105105 /** @var RouterRequest */
106- private $ request ;
106+ private RouterRequest $ request ;
107107
108108 /** @var bool */
109- private $ debug = false ;
109+ private bool $ debug = false ;
110110
111111 /**
112112 * Router constructor method.
@@ -170,7 +170,7 @@ public function __call($method, $params)
170170
171171 [$ route , $ callback ] = $ params ;
172172 $ options = $ params [2 ] ?? null ;
173- if (strstr ($ route , ': ' )) {
173+ if (str_contains ($ route , ': ' )) {
174174 $ route1 = $ route2 = '' ;
175175 foreach (explode ('/ ' , $ route ) as $ key => $ value ) {
176176 if ($ value != '' ) {
@@ -228,13 +228,13 @@ public function add(string $methods, string $route, $callback, array $options =
228228 /**
229229 * Add new route rules pattern; String or Array
230230 *
231- * @param string| array $pattern
231+ * @param array|string $pattern
232232 * @param string|null $attr
233233 *
234234 * @return mixed
235235 * @throws
236236 */
237- public function pattern ($ pattern , string $ attr = null )
237+ public function pattern (array | string $ pattern , string $ attr = null )
238238 {
239239 if (is_array ($ pattern )) {
240240 foreach ($ pattern as $ key => $ value ) {
@@ -381,7 +381,7 @@ public function controller(string $route, string $controller, array $options = [
381381 $ classMethods = get_class_methods ($ controller );
382382 if ($ classMethods ) {
383383 foreach ($ classMethods as $ methodName ) {
384- if (!strstr ($ methodName , '__ ' )) {
384+ if (!str_contains ($ methodName , '__ ' )) {
385385 $ method = 'any ' ;
386386 foreach (explode ('| ' , $ this ->request ->validMethods ()) as $ m ) {
387387 if (stripos ($ methodName , $ m = strtolower ($ m ), 0 ) === 0 ) {
@@ -741,11 +741,11 @@ protected function addRoute(string $uri, string $method, $callback, ?array $opti
741741 }
742742
743743 /**
744- * @param array|string $middleware
744+ * @param array|string|null $middleware
745745 *
746746 * @return array
747747 */
748- protected function calculateMiddleware ($ middleware ): array
748+ protected function calculateMiddleware (array | string | null $ middleware ): array
749749 {
750750 if (is_null ($ middleware )) {
751751 return [];
@@ -761,6 +761,7 @@ protected function calculateMiddleware($middleware): array
761761 * @param array $params
762762 *
763763 * @return void
764+ * @throws Exception
764765 */
765766 protected function runRouteCommand ($ command , array $ params = []): void
766767 {
0 commit comments