11
11
import fr .adrienbrault .idea .symfony2plugin .routing .Route ;
12
12
import fr .adrienbrault .idea .symfony2plugin .routing .RouteHelper ;
13
13
import fr .adrienbrault .idea .symfony2plugin .util .PhpElementsUtil ;
14
+ import fr .adrienbrault .idea .symfony2plugin .util .PhpIndexUtil ;
14
15
import fr .adrienbrault .idea .symfony2plugin .util .SymfonyBundleUtil ;
15
16
import fr .adrienbrault .idea .symfony2plugin .util .dict .SymfonyBundle ;
16
17
import fr .adrienbrault .idea .symfony2plugin .util .service .ServiceXmlParserFactory ;
@@ -28,18 +29,16 @@ public ControllerIndex(Project project) {
28
29
this .phpIndex = PhpIndex .getInstance (project );
29
30
}
30
31
31
- public ArrayList <ControllerAction > getAction () {
32
+ public List <ControllerAction > getActions () {
32
33
33
- ArrayList <ControllerAction > actions = new ArrayList <ControllerAction >();
34
+ List <ControllerAction > actions = new ArrayList <ControllerAction >();
34
35
SymfonyBundleUtil symfonyBundleUtil = new SymfonyBundleUtil (phpIndex );
35
36
36
- Collection <PhpClass > controllerClasses = phpIndex .getAllSubclasses ("\\ Symfony\\ Bundle\\ FrameworkBundle\\ Controller\\ Controller" );
37
- for (PhpClass controllerClass : controllerClasses ) {
38
- actions .addAll (this .getActionMethods (symfonyBundleUtil , controllerClass ));
37
+ for (SymfonyBundle symfonyBundle : symfonyBundleUtil .getBundles ()) {
38
+ actions .addAll (this .getActionMethods (symfonyBundle ));
39
39
}
40
40
41
41
return actions ;
42
-
43
42
}
44
43
45
44
@ Nullable
@@ -71,7 +70,7 @@ public ControllerAction getControllerActionOnService(String shortcutName) {
71
70
72
71
@ Nullable
73
72
public ControllerAction getControllerAction (String shortcutName ) {
74
- for (ControllerAction controllerAction : this .getAction ()) {
73
+ for (ControllerAction controllerAction : this .getActions ()) {
75
74
if (controllerAction .getShortcutName ().equals (shortcutName )) {
76
75
return controllerAction ;
77
76
}
@@ -80,27 +79,50 @@ public ControllerAction getControllerAction(String shortcutName) {
80
79
return null ;
81
80
}
82
81
83
- private ArrayList <ControllerAction > getActionMethods (SymfonyBundleUtil symfonyBundleUtil , PhpClass controllerClass ) {
84
-
85
- ArrayList <ControllerAction > actions = new ArrayList <ControllerAction >();
86
-
87
- Collection <Method > methods = controllerClass .getMethods ();
88
- SymfonyBundle symfonyBundle = symfonyBundleUtil .getContainingBundle (controllerClass );
82
+ private List <ControllerAction > getActionMethods (SymfonyBundle symfonyBundle ) {
89
83
90
- if (symfonyBundle == null ) {
91
- return actions ;
84
+ String namespaceName = symfonyBundle .getNamespaceName ();
85
+ if (!namespaceName .startsWith ("\\ " )) {
86
+ namespaceName = "\\ " + namespaceName ;
92
87
}
93
88
94
- String path = symfonyBundle .getRelative (controllerClass .getContainingFile ().getVirtualFile (), true );
95
- if (path == null || !path .startsWith ("Controller/" ) || !path .endsWith ("Controller" )) {
96
- return actions ;
89
+ if (!namespaceName .endsWith ("\\ " )) {
90
+ namespaceName += "\\ " ;
97
91
}
98
92
99
- for (Method method : methods ) {
100
- String methodName = method .getName ();
101
- if (methodName .endsWith ("Action" ) && method .getAccess ().isPublic ()) {
102
- String shortcutName = symfonyBundle .getName () + ":" + path .substring ("Controller/" .length (), path .length () - 10 ) + ':' + methodName .substring (0 , methodName .length () - 6 );
103
- actions .add (new ControllerAction (shortcutName , method ));
93
+ namespaceName += "Controller" ;
94
+
95
+ List <ControllerAction > actions = new ArrayList <ControllerAction >();
96
+
97
+ for (PhpClass phpClass : PhpIndexUtil .getPhpClassInsideNamespace (this .project , namespaceName )) {
98
+
99
+ if (!phpClass .getName ().endsWith ("Controller" )) {
100
+ continue ;
101
+ }
102
+
103
+ String presentableFQN = phpClass .getPresentableFQN ();
104
+ if (presentableFQN == null ) {
105
+ continue ;
106
+ }
107
+
108
+ if (!presentableFQN .startsWith ("\\ " )) {
109
+ presentableFQN = "\\ " + presentableFQN ;
110
+ }
111
+
112
+ presentableFQN = presentableFQN .substring (0 , presentableFQN .length () - "Controller" .length ());
113
+ if (presentableFQN .length () == 0 ) {
114
+ continue ;
115
+ }
116
+
117
+ String ns = presentableFQN .substring (namespaceName .length () + 1 );
118
+
119
+ for (Method method : phpClass .getMethods ()) {
120
+ String methodName = method .getName ();
121
+ if (methodName .endsWith ("Action" ) && method .getAccess ().isPublic ()) {
122
+ String shortcutName = symfonyBundle .getName () + ":" + ns .replace ("\\ " , "/" ) + ':' + methodName .substring (0 , methodName .length () - 6 );
123
+ actions .add (new ControllerAction (shortcutName , method ));
124
+ }
125
+
104
126
}
105
127
106
128
}
@@ -169,10 +191,10 @@ public Method resolveShortcutName(String controllerName) {
169
191
}
170
192
171
193
static public List <LookupElement > getControllerLookupElements (Project project ) {
172
- ArrayList <LookupElement > lookupElements = new ArrayList <LookupElement >();
194
+ List <LookupElement > lookupElements = new ArrayList <LookupElement >();
173
195
174
196
ControllerIndex controllerIndex = new ControllerIndex (project );
175
- for (ControllerAction controllerAction : controllerIndex .getAction ()) {
197
+ for (ControllerAction controllerAction : controllerIndex .getActions ()) {
176
198
lookupElements .add (new ControllerActionLookupElement (controllerAction ));
177
199
}
178
200
0 commit comments