@@ -43,7 +43,7 @@ class Router
4343 /**
4444 * Router Version
4545 */
46- const VERSION = '2.1 .0 ' ;
46+ const VERSION = '2.2 .0 ' ;
4747
4848 /**
4949 * @var string $baseFolder Pattern definitions for parameters of Route
@@ -375,6 +375,8 @@ public function controller(string $route, string $controller, array $options = [
375375 return true ;
376376 }
377377
378+ $ only = $ options ['only ' ] ?? [];
379+ $ except = $ options ['except ' ] ?? [];
378380 $ controller = $ this ->resolveClassName ($ controller );
379381 $ classMethods = get_class_methods ($ controller );
380382 if ($ classMethods ) {
@@ -390,6 +392,15 @@ public function controller(string $route, string $controller, array $options = [
390392
391393 $ methodVar = lcfirst (preg_replace ('/ ' . $ method . '/i ' , '' , $ methodName , 1 ));
392394 $ 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+
393404 $ ref = new ReflectionMethod ($ controller , $ methodName );
394405 $ endpoints = [];
395406 foreach ($ ref ->getParameters () as $ param ) {
@@ -770,9 +781,10 @@ protected function clearRouteName(string $route = ''): string
770781 */
771782 protected function getRequestUri (): string
772783 {
773- $ dirname = dirname ($ this ->request ()->server ->get ('SCRIPT_NAME ' ));
784+ $ script = $ this ->request ()->server ->get ('SCRIPT_NAME ' );
785+ $ dirname = dirname ($ script );
774786 $ dirname = $ dirname === '/ ' ? '' : $ dirname ;
775- $ basename = basename ($ _SERVER [ ' SCRIPT_NAME ' ] );
787+ $ basename = basename ($ script );
776788 $ uri = str_replace ([$ dirname , $ basename ],null , $ this ->request ()->server ->get ('REQUEST_URI ' ));
777789 return $ this ->clearRouteName (explode ('? ' , $ uri )[0 ]);
778790 }
0 commit comments