@@ -113,7 +113,8 @@ public function __construct(
113
113
array $ pluginMap = [],
114
114
array $ whitelists = [],
115
115
ClassScanner $ classScanner = null
116
- ) {
116
+ )
117
+ {
117
118
$ this ->_mapRouters = $ mapRouters ;
118
119
$ this ->_mapLayoutBlocks = $ mapLayoutBlocks ;
119
120
$ this ->configReader = $ configReader ;
@@ -146,7 +147,7 @@ public function getDependencyInfo($currentModule, $fileType, $file, &$contents)
146
147
);
147
148
$ dependenciesInfo = $ this ->considerCaseDependencies (
148
149
$ dependenciesInfo ,
149
- $ this ->_caseGetUrl ($ currentModule , $ contents )
150
+ $ this ->_caseGetUrl ($ currentModule , $ contents, $ file )
150
151
);
151
152
$ dependenciesInfo = $ this ->considerCaseDependencies (
152
153
$ dependenciesInfo ,
@@ -304,12 +305,13 @@ private function isPluginDependency($dependent, $dependency)
304
305
*
305
306
* @param string $currentModule
306
307
* @param string $contents
308
+ * @param string $file
307
309
* @return array
308
310
* @throws LocalizedException
309
311
* @throws \Exception
310
312
* @SuppressWarnings(PMD.CyclomaticComplexity)
311
313
*/
312
- protected function _caseGetUrl (string $ currentModule , string &$ contents ): array
314
+ protected function _caseGetUrl (string $ currentModule , string &$ contents, string $ file ): array
313
315
{
314
316
$ dependencies = [];
315
317
$ pattern = '#(\->|:)(?<source>getUrl\(([ \'"])(?<path>[a-zA-Z0-9\-_*\/]+)\3)\s*[,)]# ' ;
@@ -321,11 +323,7 @@ protected function _caseGetUrl(string $currentModule, string &$contents): array
321
323
$ path = $ item ['path ' ];
322
324
$ returnedDependencies = [];
323
325
if (strpos ($ path , '* ' ) !== false ) {
324
- /**
325
- * Skip processing wildcard urls since they always resolve to the current
326
- * route_front_name/area_front_name/controller_name
327
- */
328
- continue ;
326
+ $ returnedDependencies = $ this ->processWildcardUrl ($ path , $ file );
329
327
} elseif (preg_match ('#rest(?<service>/V1/\w+)#i ' , $ path , $ apiMatch )) {
330
328
$ returnedDependencies = $ this ->processApiUrl ($ apiMatch ['service ' ]);
331
329
} else {
@@ -347,6 +345,66 @@ protected function _caseGetUrl(string $currentModule, string &$contents): array
347
345
return $ dependencies ;
348
346
}
349
347
348
+ /**
349
+ * Helper method to get module dependencies used by a wildcard Url
350
+ *
351
+ * @param string $urlPath
352
+ * @param string $filePath
353
+ * @return string[]
354
+ * @throws NoSuchActionException
355
+ */
356
+ private function processWildcardUrl (string $ urlPath , string $ filePath )
357
+ {
358
+ $ filePath = strtolower ($ filePath );
359
+ $ urlRoutePieces = explode ('/ ' , $ urlPath );
360
+ $ routeId = array_shift ($ urlRoutePieces );
361
+
362
+ //Skip route wildcard processing as this requires using the routeMapper
363
+ if ('* ' === $ routeId ) {
364
+ return [];
365
+ }
366
+ $ filePathInfo = pathinfo ($ filePath );
367
+ $ fileActionName = $ filePathInfo ['filename ' ];
368
+ $ filePathPieces = explode ('/ ' , $ filePathInfo ['dirname ' ]);
369
+
370
+ /**
371
+ * Only handle Controllers. ie: Ignore Blocks, Templates, and Models due to complexity in static resolution
372
+ * of route
373
+ */
374
+ if (in_array ('block ' , $ filePathPieces )
375
+ || in_array ('model ' , $ filePathPieces )
376
+ || $ filePathInfo ['extension ' ] === 'phtml '
377
+ ) {
378
+ return [];
379
+ }
380
+ $ fileControllerIndex = array_search ('adminhtml ' , $ filePathPieces )
381
+ ?? array_search ('controller ' , $ filePathPieces );
382
+
383
+ $ controllerName = array_shift ($ urlRoutePieces );
384
+ if ('* ' === $ controllerName ) {
385
+ $ fileControllerName = implode ("_ " , array_slice ($ filePathPieces , $ fileControllerIndex + 1 ));
386
+ $ controllerName = $ fileControllerName ;
387
+ }
388
+
389
+ if (empty ($ urlRoutePieces ) || !$ urlRoutePieces [0 ]) {
390
+ return $ this ->routeMapper ->getDependencyByRoutePath (
391
+ $ routeId ,
392
+ $ controllerName ,
393
+ UrlInterface::DEFAULT_ACTION_NAME
394
+ );
395
+ }
396
+
397
+ $ actionName = array_shift ($ urlRoutePieces );
398
+ if ('* ' === $ actionName ) {
399
+ $ actionName = $ fileActionName ;
400
+ }
401
+ return $ this ->routeMapper ->getDependencyByRoutePath (
402
+ $ routeId ,
403
+ $ controllerName ,
404
+ $ actionName
405
+ );
406
+ }
407
+
350
408
/**
351
409
* Helper method to get module dependencies used by a standard URL
352
410
*
@@ -357,7 +415,7 @@ protected function _caseGetUrl(string $currentModule, string &$contents): array
357
415
private function processStandardUrl (string $ path )
358
416
{
359
417
$ pattern = '#(?<route_id>[a-z0-9\-_]{3,}) '
360
- . '\/?(?<controller_name>[a-z0-9\-_]+)?\/?(?<action_name>[a-z0-9\-_]+)?#i ' ;
418
+ . '\/?(?<controller_name>[a-z0-9\-_]+)?\/?(?<action_name>[a-z0-9\-_]+)?#i ' ;
361
419
if (preg_match ($ pattern , $ path , $ match )) {
362
420
$ routeId = $ match ['route_id ' ];
363
421
$ controllerName = $ match ['controller_name ' ] ?? UrlInterface::DEFAULT_CONTROLLER_NAME ;
0 commit comments