@@ -201,26 +201,23 @@ public static function extractRouteInfo(ReflectionMethod $method, string $api =
201201 {
202202 $ route = $ info = null ;
203203 $ docComments = $ method ->getDocComment ();
204+ $ resolvedApi = self ::resolveApiToken ($ method , $ api );
204205 $ regexpRoute = AnnotationHelper::extractRoute ($ docComments ?: '' , $ method );
205206 if (null !== $ regexpRoute ) {
206207 list ($ regex , $ default , $ params , $ requirements ) = RouterHelper::extractReflectionParams (
207208 $ regexpRoute ,
208209 $ method
209210 );
210211 $ originalRegex = $ regex ;
211- if ('' !== $ api && str_contains ($ regex , '__API__ ' )) {
212- $ regex = str_replace ('{__API__} ' , $ api , $ regex );
213- $ default = str_replace ('{__API__} ' , $ api , $ default );
214- }
215- $ regex = str_replace ('{__DOMAIN__} ' , $ module , $ regex );
216- $ default = str_replace ('{__DOMAIN__} ' , $ module , $ default );
212+ $ regex = self ::replaceRuntimeTokens ($ regex , $ resolvedApi , $ module );
213+ $ default = self ::replaceRuntimeTokens ($ default , $ resolvedApi , $ module );
217214 $ httpMethod = AnnotationHelper::extractReflectionHttpMethod ($ docComments ?: '' , $ method );
218215 $ icon = AnnotationHelper::extractDocIcon ($ docComments ?: '' , $ method );
219- $ label = ( string )AnnotationHelper:: extractReflectionLabel ( $ docComments ?: '' , $ method );
220- if ( $ label !== '' ) {
221- $ label = str_replace ( ' {__API__} ' , $ api , $ label );
222- $ label = str_replace ( ' {__DOMAIN__} ' , $ module, $ label );
223- }
216+ $ label = self :: replaceRuntimeTokens (
217+ ( string )AnnotationHelper:: extractReflectionLabel ( $ docComments ?: '' , $ method ),
218+ $ resolvedApi ,
219+ $ module
220+ );
224221 $ route = $ httpMethod . "#|# " . $ regex ;
225222 $ route = preg_replace ('/( \\r| \\f| \\t| \\n)/ ' , '' , $ route );
226223 $ info = [
@@ -230,7 +227,7 @@ public static function extractRouteInfo(ReflectionMethod $method, string $api =
230227 'pattern ' => $ originalRegex ,
231228 'label ' => $ label ,
232229 'icon ' => strlen ($ icon ) > 0 ? $ icon : '' ,
233- 'module ' => preg_replace ( ' /( \\ \| \\ /)/ ' , '' , $ module ),
230+ 'module ' => self :: normalizeRouteModule ( $ module ),
234231 'visible ' => AnnotationHelper::extractReflectionVisibility ($ docComments ?: '' , $ method ),
235232 'http ' => $ httpMethod ,
236233 'cache ' => AnnotationHelper::extractReflectionCacheability ($ docComments ?: '' , $ method ),
@@ -240,6 +237,31 @@ public static function extractRouteInfo(ReflectionMethod $method, string $api =
240237 return [$ route , $ info ];
241238 }
242239
240+ private static function resolveApiToken (ReflectionMethod $ method , string $ api ): string
241+ {
242+ $ candidate = trim ($ api );
243+ if ($ candidate !== '' ) {
244+ return $ candidate ;
245+ }
246+
247+ return $ method ->getDeclaringClass ()->getShortName ();
248+ }
249+
250+ private static function replaceRuntimeTokens (string $ value , string $ api , string $ module ): string
251+ {
252+ if ($ value === '' ) {
253+ return $ value ;
254+ }
255+
256+ $ value = str_replace ('{__API__} ' , $ api , $ value );
257+ return str_replace ('{__DOMAIN__} ' , $ module , $ value );
258+ }
259+
260+ private static function normalizeRouteModule (string $ module ): string
261+ {
262+ return preg_replace ('/( \\\| \\/)/ ' , '' , $ module );
263+ }
264+
243265 /**
244266 *
245267 * @param string $text
0 commit comments