1111
1212namespace CodeIgniter \Commands \Utilities \Routes \AutoRouterImproved ;
1313
14+ use Config \Routing ;
1415use ReflectionClass ;
1516use ReflectionMethod ;
1617
@@ -31,13 +32,18 @@ final class ControllerMethodReader
3132 */
3233 private array $ httpMethods ;
3334
35+ private bool $ translateURIDashes ;
36+
3437 /**
3538 * @param string $namespace the default namespace
3639 */
3740 public function __construct (string $ namespace , array $ httpMethods )
3841 {
3942 $ this ->namespace = $ namespace ;
4043 $ this ->httpMethods = $ httpMethods ;
44+
45+ $ config = config (Routing::class);
46+ $ this ->translateURIDashes = $ config ->translateURIDashes ;
4147 }
4248
4349 /**
@@ -67,7 +73,7 @@ public function read(string $class, string $defaultController = 'Home', string $
6773 foreach ($ this ->httpMethods as $ httpVerb ) {
6874 if (strpos ($ methodName , $ httpVerb ) === 0 ) {
6975 // Remove HTTP verb prefix.
70- $ methodInUri = lcfirst ( substr ( $ methodName , strlen ( $ httpVerb )) );
76+ $ methodInUri = $ this -> getUriByMethod ( $ httpVerb , $ methodName );
7177
7278 // Check if it is the default method.
7379 if ($ methodInUri === $ defaultMethod ) {
@@ -171,7 +177,27 @@ private function getUriByClass(string $classname): string
171177 $ classPath .= lcfirst ($ part ) . '/ ' ;
172178 }
173179
174- return rtrim ($ classPath , '/ ' );
180+ $ classUri = rtrim ($ classPath , '/ ' );
181+
182+ if ($ this ->translateURIDashes ) {
183+ $ classUri = str_replace ('_ ' , '- ' , $ classUri );
184+ }
185+
186+ return $ classUri ;
187+ }
188+
189+ /**
190+ * @return string URI path part from the method
191+ */
192+ private function getUriByMethod (string $ httpVerb , string $ methodName ): string
193+ {
194+ $ methodUri = lcfirst (substr ($ methodName , strlen ($ httpVerb )));
195+
196+ if ($ this ->translateURIDashes ) {
197+ $ methodUri = str_replace ('_ ' , '- ' , $ methodUri );
198+ }
199+
200+ return $ methodUri ;
175201 }
176202
177203 /**
0 commit comments