@@ -43,7 +43,7 @@ class Router
43
43
/**
44
44
* Router Version
45
45
*/
46
- const VERSION = '2.1 .0 ' ;
46
+ const VERSION = '2.2 .0 ' ;
47
47
48
48
/**
49
49
* @var string $baseFolder Pattern definitions for parameters of Route
@@ -375,6 +375,8 @@ public function controller(string $route, string $controller, array $options = [
375
375
return true ;
376
376
}
377
377
378
+ $ only = $ options ['only ' ] ?? [];
379
+ $ except = $ options ['except ' ] ?? [];
378
380
$ controller = $ this ->resolveClassName ($ controller );
379
381
$ classMethods = get_class_methods ($ controller );
380
382
if ($ classMethods ) {
@@ -390,6 +392,15 @@ public function controller(string $route, string $controller, array $options = [
390
392
391
393
$ methodVar = lcfirst (preg_replace ('/ ' . $ method . '/i ' , '' , $ methodName , 1 ));
392
394
$ methodVar = strtolower (preg_replace ('%([a-z]|[0-9])([A-Z])% ' , '\1-\2 ' , $ methodVar ));
395
+
396
+ if (!empty ($ only ) && !in_array ($ methodVar , $ only )) {
397
+ continue ;
398
+ }
399
+
400
+ if (!empty ($ except ) && in_array ($ methodVar , $ except )) {
401
+ continue ;
402
+ }
403
+
393
404
$ ref = new ReflectionMethod ($ controller , $ methodName );
394
405
$ endpoints = [];
395
406
foreach ($ ref ->getParameters () as $ param ) {
@@ -770,9 +781,10 @@ protected function clearRouteName(string $route = ''): string
770
781
*/
771
782
protected function getRequestUri (): string
772
783
{
773
- $ dirname = dirname ($ this ->request ()->server ->get ('SCRIPT_NAME ' ));
784
+ $ script = $ this ->request ()->server ->get ('SCRIPT_NAME ' );
785
+ $ dirname = dirname ($ script );
774
786
$ dirname = $ dirname === '/ ' ? '' : $ dirname ;
775
- $ basename = basename ($ _SERVER [ ' SCRIPT_NAME ' ] );
787
+ $ basename = basename ($ script );
776
788
$ uri = str_replace ([$ dirname , $ basename ],null , $ this ->request ()->server ->get ('REQUEST_URI ' ));
777
789
return $ this ->clearRouteName (explode ('? ' , $ uri )[0 ]);
778
790
}
0 commit comments