|
10 | 10 | import fr.adrienbrault.idea.symfony2plugin.dic.XmlServiceParser;
|
11 | 11 | import fr.adrienbrault.idea.symfony2plugin.routing.Route;
|
12 | 12 | import fr.adrienbrault.idea.symfony2plugin.routing.RouteHelper;
|
| 13 | +import fr.adrienbrault.idea.symfony2plugin.routing.dic.ServiceRouteContainer; |
13 | 14 | import fr.adrienbrault.idea.symfony2plugin.stubs.ContainerCollectionResolver;
|
14 | 15 | import fr.adrienbrault.idea.symfony2plugin.util.PhpElementsUtil;
|
15 | 16 | import fr.adrienbrault.idea.symfony2plugin.util.PhpIndexUtil;
|
16 | 17 | import fr.adrienbrault.idea.symfony2plugin.util.SymfonyBundleUtil;
|
17 | 18 | import fr.adrienbrault.idea.symfony2plugin.util.dict.ServiceUtil;
|
18 | 19 | import fr.adrienbrault.idea.symfony2plugin.util.dict.SymfonyBundle;
|
19 | 20 | import fr.adrienbrault.idea.symfony2plugin.util.service.ServiceXmlParserFactory;
|
| 21 | +import org.jetbrains.annotations.NotNull; |
20 | 22 | import org.jetbrains.annotations.Nullable;
|
21 | 23 |
|
22 | 24 | import java.util.*;
|
@@ -131,45 +133,33 @@ private List<ControllerAction> getActionMethods(SymfonyBundle symfonyBundle) {
|
131 | 133 | return actions;
|
132 | 134 | }
|
133 | 135 |
|
134 |
| - public ArrayList<ControllerAction> getServiceActionMethods(Project project) { |
| 136 | + @NotNull |
| 137 | + public List<ControllerAction> getServiceActionMethods(@NotNull Project project) { |
135 | 138 |
|
136 |
| - ArrayList<ControllerAction> actions = new ArrayList<ControllerAction>(); |
137 |
| - |
138 |
| - Map<String,Route> routes = RouteHelper.getCompiledRoutes(project); |
| 139 | + Map<String,Route> routes = RouteHelper.getAllRoutes(project); |
139 | 140 | if(routes.size() == 0) {
|
140 |
| - return actions; |
141 |
| - } |
142 |
| - |
143 |
| - ServiceMap serviceMap = ServiceXmlParserFactory.getInstance(project, XmlServiceParser.class).getServiceMap(); |
144 |
| - if(serviceMap.getMap().size() == 0) { |
145 |
| - return actions; |
| 141 | + return Collections.emptyList(); |
146 | 142 | }
|
147 | 143 |
|
148 |
| - HashMap<String, String> controllerClassNames = new HashMap<String, String>(); |
149 |
| - |
150 | 144 | // there is now way to find service controllers directly,
|
151 | 145 | // so we search for predefined service controller and use the public methods
|
152 |
| - for (Map.Entry<String,Route> entrySet: routes.entrySet()) { |
153 |
| - String controllerName = entrySet.getValue().getController(); |
154 |
| - if(controllerName != null && !controllerName.contains("::") && controllerName.contains(":")) { |
155 |
| - String serviceId = controllerName.substring(0, controllerName.lastIndexOf(":")); |
156 |
| - if(serviceMap.getMap().containsKey(serviceId)) { |
157 |
| - String className = serviceMap.getMap().get(serviceId); |
158 |
| - controllerClassNames.put(serviceId, className); |
159 |
| - } |
| 146 | + ContainerCollectionResolver.LazyServiceCollector collector = new ContainerCollectionResolver.LazyServiceCollector(project); |
| 147 | + |
| 148 | + List<ControllerAction> actions = new ArrayList<ControllerAction>(); |
| 149 | + for (String serviceName : ServiceRouteContainer.build(routes).getServiceNames()) { |
| 150 | + |
| 151 | + PhpClass phpClass = ServiceUtil.getResolvedClassDefinition(project, serviceName, collector); |
| 152 | + if(phpClass == null) { |
| 153 | + continue; |
160 | 154 | }
|
161 |
| - } |
162 | 155 |
|
163 |
| - // find public method of the service class which are possible Actions |
164 |
| - for(Map.Entry<String, String> classDefinition: controllerClassNames.entrySet()) { |
165 |
| - PhpClass phpClass = PhpElementsUtil.getClass(this.phpIndex, classDefinition.getValue()); |
166 |
| - if(phpClass != null) { |
167 |
| - for(Method method : phpClass.getMethods()) { |
168 |
| - if(method.getAccess().isPublic() && !method.getName().startsWith("__") && !method.getName().startsWith("set")) { |
169 |
| - actions.add(new ControllerAction(classDefinition.getKey() + ":" + method.getName(), method)); |
170 |
| - } |
| 156 | + // find public method of the service class which are possible Actions |
| 157 | + for(Method method : phpClass.getMethods()) { |
| 158 | + if(method.getAccess().isPublic() && !method.getName().startsWith("__") && !method.getName().startsWith("set")) { |
| 159 | + actions.add(new ControllerAction(serviceName + ":" + method.getName(), method)); |
171 | 160 | }
|
172 | 161 | }
|
| 162 | + |
173 | 163 | }
|
174 | 164 |
|
175 | 165 | return actions;
|
|
0 commit comments