14
14
import com .jetbrains .php .lang .psi .elements .StringLiteralExpression ;
15
15
import com .magento .idea .magento2plugin .magento .files .RegistrationPhp ;
16
16
import com .magento .idea .magento2plugin .util .RegExUtil ;
17
+ import java .util .regex .Matcher ;
18
+ import java .util .regex .Pattern ;
17
19
import org .jetbrains .annotations .Nullable ;
18
20
19
21
public final class GetModuleNameByDirectoryUtil {
20
- public static final int THEME_SPLIT_COUNT = 1 ;
21
- public static final String THEME_DIRECTORY_REGEX = "app\\ /design\\ /(adminhtml|frontend)\\ /" ;
22
22
23
23
private GetModuleNameByDirectoryUtil () {}
24
24
@@ -34,10 +34,14 @@ public static String execute(
34
34
final Project project
35
35
) {
36
36
// Check if directory is theme directory and return module name from directory path if yes
37
- final String [] splits = psiDirectory .getVirtualFile ().getPath ()
38
- .split (THEME_DIRECTORY_REGEX );
39
- if (splits .length > THEME_SPLIT_COUNT ) {
40
- return splits [1 ].split ("\\ /" )[2 ];
37
+ final String path = psiDirectory .getVirtualFile ().getPath ();
38
+ final Pattern pattern = Pattern .compile (RegExUtil .CustomTheme .MODULE_NAME );
39
+ final Matcher matcher = pattern .matcher (path );
40
+ while (matcher .find ()) {
41
+ final String moduleNamePath = matcher .group (0 );
42
+ if (!moduleNamePath .isEmpty ()) {
43
+ return moduleNamePath .split ("/" )[5 ];
44
+ }
41
45
}
42
46
43
47
final PhpFile registrationPhp = getRegistrationPhpRecursively (
0 commit comments