@@ -106,8 +106,21 @@ public function getOptionsRoute():string
106106 {
107107 //@TODO: re-check
108108 if ($ this ->prefix && !empty ($ this ->prefixSettings )) {
109- $ prefix = $ this ->prefixSettings ['module ' ] ?? $ this ->prefix ;
110- return trim ($ prefix , '/ ' ).'/ ' .$ this ->controllerId .'/options ' ;
109+ // $prefix = $this->prefixSettings['module'] ?? $this->prefix;
110+ if (isset ($ this ->prefixSettings ['module ' ])) {
111+ $ prefix = $ this ->prefixSettings ['module ' ];
112+ return trim ($ prefix , '/ ' ) . '/ ' . $ this ->controllerId . '/options ' ;
113+ } elseif (isset ($ this ->prefixSettings ['namespace ' ]) && str_contains ($ this ->prefixSettings ['namespace ' ], '\modules \\' )) {
114+ $ prefix = static ::computeModule ('\\' , $ this ->prefixSettings ['namespace ' ]);
115+ if ($ prefix ) {
116+ return trim ($ prefix , '/ ' ) . '/ ' . $ this ->controllerId . '/options ' ;
117+ }
118+ } elseif (isset ($ this ->prefixSettings ['path ' ]) && str_contains ($ this ->prefixSettings ['path ' ], '/modules/ ' )) {
119+ $ prefix = static ::computeModule ('/ ' , $ this ->prefixSettings ['path ' ]);
120+ if ($ prefix ) {
121+ return trim ($ prefix , '/ ' ) . '/ ' . $ this ->controllerId . '/options ' ;
122+ }
123+ }
111124 }
112125 return $ this ->controllerId .'/options ' ;
113126 }
@@ -251,4 +264,29 @@ public function getIdParamType(): string
251264 }
252265 return $ this ->params [$ this ->idParam ]['type ' ] === 'integer ' ? 'int ' : 'string ' ;
253266 }
267+
268+ /**
269+ * @param string $separator
270+ * @param string $entity path or namespace
271+ * @return void
272+ */
273+ public static function computeModule (string $ separator , string $ entity ): ?string
274+ {
275+ $ parts = explode ($ separator . 'modules ' . $ separator , $ entity );
276+ if (empty ($ parts [1 ])) {
277+ return null ;
278+ }
279+ if (str_contains ($ parts [1 ], 'controller ' )) {
280+ $ result = explode ($ separator . 'controller ' , $ parts [1 ]);
281+ $ result = array_map (function ($ val ) {
282+ return str_replace ('\\' , '/ ' , $ val );
283+ }, $ result );
284+ } else {
285+ $ result = explode ($ separator , $ parts [1 ]);
286+ }
287+ if (empty ($ result [0 ])) {
288+ return null ;
289+ }
290+ return $ result [0 ];
291+ }
254292}
0 commit comments