@@ -40,7 +40,7 @@ class Router
40
40
/**
41
41
* Router Version
42
42
*/
43
- const VERSION = '2.3.0 ' ;
43
+ const VERSION = '2.3.4 ' ;
44
44
45
45
/**
46
46
* @var string $baseFolder Pattern definitions for parameters of Route
@@ -133,8 +133,8 @@ class Router
133
133
/**
134
134
* Router constructor method.
135
135
*
136
- * @param array $params
137
- * @param Request|null $request
136
+ * @param array $params
137
+ * @param Request|null $request
138
138
* @param Response|null $response
139
139
*/
140
140
public function __construct (array $ params = [], Request $ request = null , Response $ response = null )
@@ -211,10 +211,10 @@ public function __call($method, $params)
211
211
/**
212
212
* Add new route method one or more http methods.
213
213
*
214
- * @param string $methods
215
- * @param string $route
214
+ * @param string $methods
215
+ * @param string $route
216
216
* @param string|closure $callback
217
- * @param array $options
217
+ * @param array $options
218
218
*
219
219
* @return bool
220
220
*/
@@ -241,12 +241,12 @@ public function add(string $methods, string $route, $callback, array $options =
241
241
* Add new route rules pattern; String or Array
242
242
*
243
243
* @param string|array $pattern
244
- * @param null| string $attr
244
+ * @param string|null $attr
245
245
*
246
246
* @return mixed
247
247
* @throws
248
248
*/
249
- public function pattern ($ pattern , $ attr = null )
249
+ public function pattern ($ pattern , string $ attr = null )
250
250
{
251
251
if (is_array ($ pattern )) {
252
252
foreach ($ pattern as $ key => $ value ) {
@@ -340,9 +340,9 @@ public function run(): void
340
340
/**
341
341
* Routes Group
342
342
*
343
- * @param string $prefix
344
- * @param closure $callback
345
- * @param array $options
343
+ * @param string $prefix
344
+ * @param Closure $callback
345
+ * @param array $options
346
346
*
347
347
* @return bool
348
348
*/
@@ -359,9 +359,7 @@ public function group(string $prefix, Closure $callback, array $options = []): b
359
359
360
360
array_push ($ this ->groups , $ group );
361
361
362
- if (is_object ($ callback )) {
363
- call_user_func_array ($ callback , [$ this ]);
364
- }
362
+ call_user_func_array ($ callback , [$ this ]);
365
363
366
364
$ this ->endGroup ();
367
365
@@ -373,7 +371,7 @@ public function group(string $prefix, Closure $callback, array $options = []): b
373
371
*
374
372
* @param string $route
375
373
* @param string $controller
376
- * @param array $options
374
+ * @param array $options
377
375
*
378
376
* @return mixed
379
377
* @throws
@@ -543,7 +541,7 @@ public function getMiddlewares(): array
543
541
/**
544
542
* Detect Routes Middleware; before or after
545
543
*
546
- * @param array $middleware
544
+ * @param array $middleware
547
545
* @param string $type
548
546
*
549
547
* @return void
@@ -573,12 +571,12 @@ protected function response(): Response
573
571
* Throw new Exception for Router Error
574
572
*
575
573
* @param string $message
576
- * @param int $statusCode
574
+ * @param int $statusCode
577
575
*
578
576
* @return RouterException
579
577
* @throws Exception
580
578
*/
581
- protected function exception ($ message = '' , int $ statusCode = 500 ): RouterException
579
+ protected function exception (string $ message = '' , int $ statusCode = 500 ): RouterException
582
580
{
583
581
return new RouterException ($ message , $ statusCode );
584
582
}
@@ -612,21 +610,21 @@ protected function setPaths(array $params): void
612
610
613
611
if (isset ($ params ['paths ' ]) && $ paths = $ params ['paths ' ]) {
614
612
$ this ->paths ['controllers ' ] = isset ($ paths ['controllers ' ])
615
- ? trim ($ paths ['controllers ' ], '/ ' )
613
+ ? rtrim ($ paths ['controllers ' ], '/ ' )
616
614
: $ this ->paths ['controllers ' ];
617
615
618
616
$ this ->paths ['middlewares ' ] = isset ($ paths ['middlewares ' ])
619
- ? trim ($ paths ['middlewares ' ], '/ ' )
617
+ ? rtrim ($ paths ['middlewares ' ], '/ ' )
620
618
: $ this ->paths ['middlewares ' ];
621
619
}
622
620
623
621
if (isset ($ params ['namespaces ' ]) && $ namespaces = $ params ['namespaces ' ]) {
624
622
$ this ->namespaces ['controllers ' ] = isset ($ namespaces ['controllers ' ])
625
- ? trim ($ namespaces ['controllers ' ], '\\' ) . '\\'
623
+ ? rtrim ($ namespaces ['controllers ' ], '\\' ) . '\\'
626
624
: '' ;
627
625
628
626
$ this ->namespaces ['middlewares ' ] = isset ($ namespaces ['middlewares ' ])
629
- ? trim ($ namespaces ['middlewares ' ], '\\' ) . '\\'
627
+ ? rtrim ($ namespaces ['middlewares ' ], '\\' ) . '\\'
630
628
: '' ;
631
629
}
632
630
@@ -638,7 +636,7 @@ protected function setPaths(array $params): void
638
636
$ this ->mainMethod = $ params ['main_method ' ];
639
637
}
640
638
641
- $ this ->cacheFile = isset ( $ params ['cache ' ]) ? $ params [ ' cache ' ] : realpath (__DIR__ . '/../cache.php ' );
639
+ $ this ->cacheFile = $ params ['cache ' ] ?? realpath (__DIR__ . '/../cache.php ' );
642
640
}
643
641
644
642
/**
@@ -694,11 +692,11 @@ protected function loadCache(): bool
694
692
* @param string $uri
695
693
* @param string $method
696
694
* @param $callback
697
- * @param array $options
695
+ * @param array|null $options
698
696
*
699
697
* @return void
700
698
*/
701
- protected function addRoute (string $ uri , string $ method , $ callback , $ options = [] )
699
+ protected function addRoute (string $ uri , string $ method , $ callback , ? array $ options = null )
702
700
{
703
701
$ groupUri = '' ;
704
702
$ groupStack = [];
@@ -752,11 +750,11 @@ protected function calculateMiddleware($middleware): array
752
750
* Run Route Command; Controller or Closure
753
751
*
754
752
* @param $command
755
- * @param $params
753
+ * @param array $params
756
754
*
757
755
* @return void
758
756
*/
759
- protected function runRouteCommand ($ command , $ params = [])
757
+ protected function runRouteCommand ($ command , array $ params = [])
760
758
{
761
759
$ this ->routerCommand ()->runRoute ($ command , $ params );
762
760
}
@@ -787,7 +785,7 @@ protected function clearRouteName(string $route = ''): string
787
785
*/
788
786
protected function getRequestUri (): string
789
787
{
790
- $ script = $ this ->request ()->server ->get ('SCRIPT_NAME ' );
788
+ $ script = $ this ->request ()->server ->get ('SCRIPT_FILENAME ' ) ?? $ this -> request ()-> server -> get ( ' SCRIPT_NAME ' );
791
789
$ dirname = dirname ($ script );
792
790
$ dirname = $ dirname === '/ ' ? '' : $ dirname ;
793
791
$ basename = basename ($ script );
0 commit comments