Skip to content

Commit 454cd3b

Browse files
committed
there so no need to iterate over all route names we already know them
1 parent 4a15650 commit 454cd3b

File tree

2 files changed

+23
-24
lines changed

2 files changed

+23
-24
lines changed

src/fr/adrienbrault/idea/symfony2plugin/routing/Route.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public Route(String name, HashMap<String, String> variables, HashMap<String, Str
2828
this.tokens = tokens;
2929

3030
if(defaults.containsKey("_controller")) {
31-
this.controller = defaults.get("_controller");
31+
this.controller = defaults.get("_controller").replace("\\\\", "\\");
3232
}
3333
}
3434

@@ -46,7 +46,6 @@ public String getController() {
4646
return controller;
4747
}
4848

49-
5049
public HashMap<String, String> getVariables() {
5150
return variables;
5251
}

src/fr/adrienbrault/idea/symfony2plugin/routing/RouteHelper.java

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,38 +26,38 @@ public class RouteHelper {
2626
public static PsiElement[] getMethods(Project project, String routeName) {
2727

2828
Symfony2ProjectComponent symfony2ProjectComponent = project.getComponent(Symfony2ProjectComponent.class);
29-
Map<String,Route> routes = symfony2ProjectComponent.getRoutes();
3029

31-
for (Route route : routes.values()) {
32-
if(route.getName().equals(routeName)) {
33-
String controllerName = route.getController();
30+
if(!symfony2ProjectComponent.getRoutes().containsKey(routeName)) {
31+
return new PsiElement[0];
32+
}
3433

35-
// convert to class: FooBundle\Controller\BarController::fooBarAction
36-
// convert to class: foo_service_bar:fooBar
37-
if(controllerName.contains("::")) {
38-
String className = controllerName.substring(0, controllerName.lastIndexOf("::"));
39-
String methodName = controllerName.substring(controllerName.lastIndexOf("::") + 2);
34+
Route route = symfony2ProjectComponent.getRoutes().get(routeName);
4035

41-
PhpIndex phpIndex = PhpIndex.getInstance(project);
42-
Collection<? extends PhpNamedElement> methodCalls = phpIndex.getBySignature("#M#C\\" + className + "." + methodName, null, 0);
43-
return methodCalls.toArray(new PsiElement[methodCalls.size()]);
36+
String controllerName = route.getController();
37+
if(controllerName == null) {
38+
return new PsiElement[0];
39+
}
4440

45-
} else if(controllerName.contains(":")) {
46-
ControllerIndex controllerIndex = new ControllerIndex(project);
41+
// convert to class: FooBundle\Controller\BarController::fooBarAction
42+
// convert to class: foo_service_bar:fooBar
43+
if(controllerName.contains("::")) {
44+
String className = controllerName.substring(0, controllerName.lastIndexOf("::"));
45+
String methodName = controllerName.substring(controllerName.lastIndexOf("::") + 2);
4746

48-
ControllerAction controllerServiceAction = controllerIndex.getControllerActionOnService(controllerName);
49-
if(controllerServiceAction != null) {
50-
return new PsiElement[] {controllerServiceAction.getMethod()};
51-
}
47+
return PhpElementsUtil.getPsiElementsBySignature(project, "#M#C\\" + className + "." + methodName);
5248

53-
}
49+
} else if(controllerName.contains(":")) {
50+
ControllerIndex controllerIndex = new ControllerIndex(project);
5451

55-
return new PsiElement[0];
52+
ControllerAction controllerServiceAction = controllerIndex.getControllerActionOnService(controllerName);
53+
if(controllerServiceAction != null) {
54+
return new PsiElement[] {controllerServiceAction.getMethod()};
5655
}
5756

5857
}
5958

6059
return new PsiElement[0];
60+
6161
}
6262

6363
private static <E> ArrayList<E> makeCollection(Iterable<E> iter) {
@@ -79,7 +79,7 @@ public static Map<String, Route> getRoutes(Project project, VirtualFile virtualF
7979

8080
PsiFile psiFile = PsiElementUtils.virtualFileToPsiFile(project, virtualFile);
8181
if(!(psiFile instanceof PhpFile)) {
82-
82+
return routes;
8383
}
8484

8585
// heavy stuff here, to get nested routing array :)
@@ -136,7 +136,7 @@ private static Route convertRouteConfig(String routeName, ArrayCreationExpressio
136136
defaults = PhpElementsUtil.getArrayKeyValueMap((ArrayCreationExpression) hashElementCollection.get(1).getValue());
137137
}
138138

139-
HashMap<String, String> requirements = new HashMap<String, String>();
139+
HashMap<String, String>requirements = new HashMap<String, String>();
140140
if(hashElementCollection.size() >= 3 && hashElementCollection.get(2).getValue() instanceof ArrayCreationExpression) {
141141
requirements = PhpElementsUtil.getArrayKeyValueMap((ArrayCreationExpression) hashElementCollection.get(2).getValue());
142142
}

0 commit comments

Comments
 (0)