13
13
import fr .adrienbrault .idea .symfony2plugin .util .SymfonyBundleUtil ;
14
14
import fr .adrienbrault .idea .symfony2plugin .util .dict .ServiceUtil ;
15
15
import fr .adrienbrault .idea .symfony2plugin .util .dict .SymfonyBundle ;
16
+ import org .apache .commons .lang .StringUtils ;
16
17
import org .jetbrains .annotations .NotNull ;
17
18
import org .jetbrains .annotations .Nullable ;
18
19
@@ -31,6 +32,7 @@ public ControllerIndex(@NotNull Project project) {
31
32
this .project = project ;
32
33
}
33
34
35
+ @ NotNull
34
36
public Collection <ControllerAction > getActions () {
35
37
Collection <ControllerAction > actions = new ArrayList <>();
36
38
@@ -65,8 +67,8 @@ public ControllerAction getControllerActionOnService(String shortcutName) {
65
67
return new ControllerAction (serviceId , method );
66
68
}
67
69
68
- private List < ControllerAction > getActionMethods ( SymfonyBundle symfonyBundle ) {
69
-
70
+ @ NotNull
71
+ private Collection < ControllerAction > getActionMethods ( @ NotNull SymfonyBundle symfonyBundle ) {
70
72
String namespaceName = symfonyBundle .getNamespaceName ();
71
73
if (!namespaceName .startsWith ("\\ " )) {
72
74
namespaceName = "\\ " + namespaceName ;
@@ -81,12 +83,15 @@ private List<ControllerAction> getActionMethods(SymfonyBundle symfonyBundle) {
81
83
List <ControllerAction > actions = new ArrayList <>();
82
84
83
85
for (PhpClass phpClass : PhpIndexUtil .getPhpClassInsideNamespace (this .project , namespaceName )) {
84
-
85
86
if (!phpClass .getName ().endsWith ("Controller" )) {
86
87
continue ;
87
88
}
88
89
89
90
String presentableFQN = phpClass .getPresentableFQN ();
91
+ if (presentableFQN .contains ("\\ Test\\ " ) || presentableFQN .contains ("\\ Tests\\ " ) || presentableFQN .startsWith ("Test\\ " ) || presentableFQN .startsWith ("\\ Test\\ " )) {
92
+ continue ;
93
+ }
94
+
90
95
if (!presentableFQN .startsWith ("\\ " )) {
91
96
presentableFQN = "\\ " + presentableFQN ;
92
97
}
@@ -100,13 +105,22 @@ private List<ControllerAction> getActionMethods(SymfonyBundle symfonyBundle) {
100
105
101
106
for (Method method : phpClass .getMethods ()) {
102
107
String methodName = method .getName ();
103
- if (methodName .endsWith ("Action" ) && method .getAccess ().isPublic ()) {
108
+ if (!method .getAccess ().isPublic () || (method .getName ().startsWith ("__" ) && !method .getName ().equals ("__invoke" ))) {
109
+ continue ;
110
+ }
111
+
112
+ if (methodName .endsWith ("Action" )) {
104
113
String shortcutName = symfonyBundle .getName () + ":" + ns .replace ("/" , "\\ " ) + ':' + methodName .substring (0 , methodName .length () - 6 );
105
114
actions .add (new ControllerAction (shortcutName , method ));
106
115
}
107
116
117
+ String shortcutName = StringUtils .stripStart (phpClass .getPresentableFQN (), "\\ " );
118
+ if (methodName .equals ("__invoke" )) {
119
+ actions .add (new ControllerAction (shortcutName , method ));
120
+ } else {
121
+ actions .add (new ControllerAction (shortcutName + "::" + method .getName (), method ));
122
+ }
108
123
}
109
-
110
124
}
111
125
112
126
return actions ;
0 commit comments