@@ -40,7 +40,7 @@ class Router
4040 /**
4141 * Router Version
4242 */
43- const VERSION = '2.3.0 ' ;
43+ const VERSION = '2.3.4 ' ;
4444
4545 /**
4646 * @var string $baseFolder Pattern definitions for parameters of Route
@@ -133,8 +133,8 @@ class Router
133133 /**
134134 * Router constructor method.
135135 *
136- * @param array $params
137- * @param Request|null $request
136+ * @param array $params
137+ * @param Request|null $request
138138 * @param Response|null $response
139139 */
140140 public function __construct (array $ params = [], Request $ request = null , Response $ response = null )
@@ -211,10 +211,10 @@ public function __call($method, $params)
211211 /**
212212 * Add new route method one or more http methods.
213213 *
214- * @param string $methods
215- * @param string $route
214+ * @param string $methods
215+ * @param string $route
216216 * @param string|closure $callback
217- * @param array $options
217+ * @param array $options
218218 *
219219 * @return bool
220220 */
@@ -241,12 +241,12 @@ public function add(string $methods, string $route, $callback, array $options =
241241 * Add new route rules pattern; String or Array
242242 *
243243 * @param string|array $pattern
244- * @param null| string $attr
244+ * @param string|null $attr
245245 *
246246 * @return mixed
247247 * @throws
248248 */
249- public function pattern ($ pattern , $ attr = null )
249+ public function pattern ($ pattern , string $ attr = null )
250250 {
251251 if (is_array ($ pattern )) {
252252 foreach ($ pattern as $ key => $ value ) {
@@ -340,9 +340,9 @@ public function run(): void
340340 /**
341341 * Routes Group
342342 *
343- * @param string $prefix
344- * @param closure $callback
345- * @param array $options
343+ * @param string $prefix
344+ * @param Closure $callback
345+ * @param array $options
346346 *
347347 * @return bool
348348 */
@@ -359,9 +359,7 @@ public function group(string $prefix, Closure $callback, array $options = []): b
359359
360360 array_push ($ this ->groups , $ group );
361361
362- if (is_object ($ callback )) {
363- call_user_func_array ($ callback , [$ this ]);
364- }
362+ call_user_func_array ($ callback , [$ this ]);
365363
366364 $ this ->endGroup ();
367365
@@ -373,7 +371,7 @@ public function group(string $prefix, Closure $callback, array $options = []): b
373371 *
374372 * @param string $route
375373 * @param string $controller
376- * @param array $options
374+ * @param array $options
377375 *
378376 * @return mixed
379377 * @throws
@@ -543,7 +541,7 @@ public function getMiddlewares(): array
543541 /**
544542 * Detect Routes Middleware; before or after
545543 *
546- * @param array $middleware
544+ * @param array $middleware
547545 * @param string $type
548546 *
549547 * @return void
@@ -573,12 +571,12 @@ protected function response(): Response
573571 * Throw new Exception for Router Error
574572 *
575573 * @param string $message
576- * @param int $statusCode
574+ * @param int $statusCode
577575 *
578576 * @return RouterException
579577 * @throws Exception
580578 */
581- protected function exception ($ message = '' , int $ statusCode = 500 ): RouterException
579+ protected function exception (string $ message = '' , int $ statusCode = 500 ): RouterException
582580 {
583581 return new RouterException ($ message , $ statusCode );
584582 }
@@ -612,21 +610,21 @@ protected function setPaths(array $params): void
612610
613611 if (isset ($ params ['paths ' ]) && $ paths = $ params ['paths ' ]) {
614612 $ this ->paths ['controllers ' ] = isset ($ paths ['controllers ' ])
615- ? trim ($ paths ['controllers ' ], '/ ' )
613+ ? rtrim ($ paths ['controllers ' ], '/ ' )
616614 : $ this ->paths ['controllers ' ];
617615
618616 $ this ->paths ['middlewares ' ] = isset ($ paths ['middlewares ' ])
619- ? trim ($ paths ['middlewares ' ], '/ ' )
617+ ? rtrim ($ paths ['middlewares ' ], '/ ' )
620618 : $ this ->paths ['middlewares ' ];
621619 }
622620
623621 if (isset ($ params ['namespaces ' ]) && $ namespaces = $ params ['namespaces ' ]) {
624622 $ this ->namespaces ['controllers ' ] = isset ($ namespaces ['controllers ' ])
625- ? trim ($ namespaces ['controllers ' ], '\\' ) . '\\'
623+ ? rtrim ($ namespaces ['controllers ' ], '\\' ) . '\\'
626624 : '' ;
627625
628626 $ this ->namespaces ['middlewares ' ] = isset ($ namespaces ['middlewares ' ])
629- ? trim ($ namespaces ['middlewares ' ], '\\' ) . '\\'
627+ ? rtrim ($ namespaces ['middlewares ' ], '\\' ) . '\\'
630628 : '' ;
631629 }
632630
@@ -638,7 +636,7 @@ protected function setPaths(array $params): void
638636 $ this ->mainMethod = $ params ['main_method ' ];
639637 }
640638
641- $ this ->cacheFile = isset ( $ params ['cache ' ]) ? $ params [ ' cache ' ] : realpath (__DIR__ . '/../cache.php ' );
639+ $ this ->cacheFile = $ params ['cache ' ] ?? realpath (__DIR__ . '/../cache.php ' );
642640 }
643641
644642 /**
@@ -694,11 +692,11 @@ protected function loadCache(): bool
694692 * @param string $uri
695693 * @param string $method
696694 * @param $callback
697- * @param array $options
695+ * @param array|null $options
698696 *
699697 * @return void
700698 */
701- protected function addRoute (string $ uri , string $ method , $ callback , $ options = [] )
699+ protected function addRoute (string $ uri , string $ method , $ callback , ? array $ options = null )
702700 {
703701 $ groupUri = '' ;
704702 $ groupStack = [];
@@ -752,11 +750,11 @@ protected function calculateMiddleware($middleware): array
752750 * Run Route Command; Controller or Closure
753751 *
754752 * @param $command
755- * @param $params
753+ * @param array $params
756754 *
757755 * @return void
758756 */
759- protected function runRouteCommand ($ command , $ params = [])
757+ protected function runRouteCommand ($ command , array $ params = [])
760758 {
761759 $ this ->routerCommand ()->runRoute ($ command , $ params );
762760 }
@@ -787,7 +785,7 @@ protected function clearRouteName(string $route = ''): string
787785 */
788786 protected function getRequestUri (): string
789787 {
790- $ script = $ this ->request ()->server ->get ('SCRIPT_NAME ' );
788+ $ script = $ this ->request ()->server ->get ('SCRIPT_FILENAME ' ) ?? $ this -> request ()-> server -> get ( ' SCRIPT_NAME ' );
791789 $ dirname = dirname ($ script );
792790 $ dirname = $ dirname === '/ ' ? '' : $ dirname ;
793791 $ basename = basename ($ script );
0 commit comments