Skip to content

Commit beb0da7

Browse files
committed
support finalized Symfony 3.4 ControllerTrait shortcuts
1 parent eff58f7 commit beb0da7

File tree

8 files changed

+43
-11
lines changed

8 files changed

+43
-11
lines changed

src/fr/adrienbrault/idea/symfony2plugin/config/SymfonyPhpReferenceContributor.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ public class SymfonyPhpReferenceContributor extends PsiReferenceContributor {
2525

2626
private static MethodMatcher.CallToSignature[] CONTAINER_SIGNATURES = new MethodMatcher.CallToSignature[] {
2727
new MethodMatcher.CallToSignature("\\Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller", "get"),
28+
new MethodMatcher.CallToSignature("\\Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller", "has"),
29+
30+
// Symfony 3.3 / 3.4
31+
new MethodMatcher.CallToSignature("\\Symfony\\Bundle\\FrameworkBundle\\Controller\\ControllerTrait", "get"),
32+
new MethodMatcher.CallToSignature("\\Symfony\\Bundle\\FrameworkBundle\\Controller\\ControllerTrait", "has"),
33+
2834
new MethodMatcher.CallToSignature("\\Symfony\\Component\\DependencyInjection\\ContainerInterface", "get"),
2935
new MethodMatcher.CallToSignature("\\Symfony\\Component\\DependencyInjection\\ContainerInterface", "has"),
3036
new MethodMatcher.CallToSignature("\\Psr\\Container\\ContainerInterface", "get"),
@@ -57,6 +63,12 @@ public class SymfonyPhpReferenceContributor extends PsiReferenceContributor {
5763
new MethodMatcher.CallToSignature("\\Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller", "render"),
5864
new MethodMatcher.CallToSignature("\\Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller", "renderView"),
5965
new MethodMatcher.CallToSignature("\\Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller", "stream"),
66+
67+
// Symfony 3.3 / 3.4
68+
new MethodMatcher.CallToSignature("\\Symfony\\Bundle\\FrameworkBundle\\Controller\\ControllerTrait", "render"),
69+
new MethodMatcher.CallToSignature("\\Symfony\\Bundle\\FrameworkBundle\\Controller\\ControllerTrait", "renderView"),
70+
new MethodMatcher.CallToSignature("\\Symfony\\Bundle\\FrameworkBundle\\Controller\\ControllerTrait", "stream"),
71+
6072
new MethodMatcher.CallToSignature("\\Twig_Environment", "render"),
6173
new MethodMatcher.CallToSignature("\\Twig_Environment", "loadTemplate"),
6274
new MethodMatcher.CallToSignature("\\Twig_Environment", "getTemplateClass"),

src/fr/adrienbrault/idea/symfony2plugin/config/php/PhpConfigReferenceContributor.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ public void registerReferenceProviders(@NotNull PsiReferenceRegistrar psiReferen
2828
.addCall("\\Symfony\\Component\\DependencyInjection\\ContainerInterface", "has")
2929
.addCall("\\Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller", "has")
3030
.addCall("\\Psr\\Container\\ContainerInterface", "has")
31+
32+
// Symfony 3.3 / 3.4
33+
.addCall("\\Symfony\\Bundle\\FrameworkBundle\\Controller\\ControllerTrait", "has")
3134
);
3235

3336
psiReferenceRegistrar.registerReferenceProvider(PhpElementsUtil.getMethodWithFirstStringPattern(), new PhpStringLiteralExpressionReference(ServiceIndexedReference.class)

src/fr/adrienbrault/idea/symfony2plugin/dic/SymfonyContainerTypeProvider.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
import com.jetbrains.php.lang.psi.resolve.types.PhpType;
1111
import com.jetbrains.php.lang.psi.resolve.types.PhpTypeProvider3;
1212
import fr.adrienbrault.idea.symfony2plugin.Settings;
13+
import fr.adrienbrault.idea.symfony2plugin.dic.container.util.ServiceContainerUtil;
1314
import fr.adrienbrault.idea.symfony2plugin.stubs.ContainerCollectionResolver;
14-
import fr.adrienbrault.idea.symfony2plugin.util.MethodMatcher;
1515
import fr.adrienbrault.idea.symfony2plugin.util.PhpElementsUtil;
1616
import fr.adrienbrault.idea.symfony2plugin.util.PhpTypeProviderUtil;
1717
import org.jetbrains.annotations.Nullable;
@@ -25,12 +25,6 @@
2525
* @author Daniel Espendiller <daniel@espendiller.net>
2626
*/
2727
public class SymfonyContainerTypeProvider implements PhpTypeProvider3 {
28-
private static MethodMatcher.CallToSignature[] SERVICE_GET_SIGNATURES = new MethodMatcher.CallToSignature[] {
29-
new MethodMatcher.CallToSignature("\\Symfony\\Component\\DependencyInjection\\ContainerInterface", "get"),
30-
new MethodMatcher.CallToSignature("\\Psr\\Container\\ContainerInterface", "get"),
31-
new MethodMatcher.CallToSignature("\\Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller", "get"),
32-
};
33-
3428
private static char TRIM_KEY = '\u0182';
3529

3630
@Override
@@ -86,7 +80,7 @@ public Collection<? extends PhpNamedElement> getBySignature(String expression, S
8680
}
8781

8882
// finally search the classes
89-
if(PhpElementsUtil.isMethodInstanceOf((Method) phpNamedElement, SERVICE_GET_SIGNATURES)) {
83+
if(PhpElementsUtil.isMethodInstanceOf((Method) phpNamedElement, ServiceContainerUtil.SERVICE_GET_SIGNATURES)) {
9084
ContainerService containerService = ContainerCollectionResolver.getService(project, parameter);
9185

9286
if(containerService != null) {

src/fr/adrienbrault/idea/symfony2plugin/dic/container/util/ServiceContainerUtil.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ public class ServiceContainerUtil {
5050
new MethodMatcher.CallToSignature("\\Symfony\\Component\\DependencyInjection\\ContainerInterface", "get"),
5151
new MethodMatcher.CallToSignature("\\Psr\\Container\\ContainerInterface", "get"),
5252
new MethodMatcher.CallToSignature("\\Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller", "get"),
53+
54+
// Symfony 3.3 / 3.4
55+
new MethodMatcher.CallToSignature("\\Symfony\\Bundle\\FrameworkBundle\\Controller\\ControllerTrait", "get"),
5356
};
5457

5558
private static String[] LOWER_PRIORITY = new String[] {

src/fr/adrienbrault/idea/symfony2plugin/form/FormGotoCompletionRegistrar.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ public void register(GotoCompletionRegistrarParameter registrar) {
9797

9898
MethodMatcher.MethodMatchParameter methodMatchParameter = new MethodMatcher.ArrayParameterMatcher(parent, 2)
9999
.withSignature("\\Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller", "createForm")
100+
101+
// Symfony 3.3 / 3.4
102+
.withSignature("\\Symfony\\Bundle\\FrameworkBundle\\Controller\\ControllerTrait", "createForm")
103+
100104
.withSignature("\\Symfony\\Component\\Form\\FormFactoryInterface", "create")
101105
.withSignature("\\Symfony\\Component\\Form\\FormFactory", "createBuilder")
102106
.match();

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,20 @@ public class PhpRouteReferenceContributor extends PsiReferenceContributor {
2020
public static MethodMatcher.CallToSignature[] GENERATOR_SIGNATURES = new MethodMatcher.CallToSignature[] {
2121
new MethodMatcher.CallToSignature("\\Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller", "generateUrl"),
2222
new MethodMatcher.CallToSignature("\\Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller", "redirectToRoute"),
23+
24+
// Symfony 3.3 / 3.4
25+
new MethodMatcher.CallToSignature("\\Symfony\\Bundle\\FrameworkBundle\\Controller\\ControllerTrait", "generateUrl"),
26+
new MethodMatcher.CallToSignature("\\Symfony\\Bundle\\FrameworkBundle\\Controller\\ControllerTrait", "redirectToRoute"),
27+
2328
new MethodMatcher.CallToSignature("\\Symfony\\Component\\Routing\\Generator\\UrlGeneratorInterface", "generate"),
29+
2430
};
2531

2632
private static MethodMatcher.CallToSignature[] FORWARD_SIGNATURES = new MethodMatcher.CallToSignature[] {
27-
new MethodMatcher.CallToSignature("\\Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller", "forward")
33+
new MethodMatcher.CallToSignature("\\Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller", "forward"),
34+
35+
// Symfony 3.3 / 3.4
36+
new MethodMatcher.CallToSignature("\\Symfony\\Bundle\\FrameworkBundle\\Controller\\ControllerTrait", "forward")
2837
};
2938

3039
@Override

src/fr/adrienbrault/idea/symfony2plugin/security/VoterGotoCompletionRegistrar.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ public void register(GotoCompletionRegistrarParameter registrar) {
4949
MethodMatcher.MethodMatchParameter methodMatchParameter = new MethodMatcher.StringParameterRecursiveMatcher(context, 0)
5050
.withSignature("Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller", "isGranted")
5151
.withSignature("Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller", "denyAccessUnlessGranted")
52+
53+
// Symfony 3.3 / 3.4
54+
.withSignature("Symfony\\Bundle\\FrameworkBundle\\Controller\\ControllerTrait", "isGranted")
55+
.withSignature("Symfony\\Bundle\\FrameworkBundle\\Controller\\ControllerTrait", "denyAccessUnlessGranted")
56+
5257
.withSignature("Symfony\\Component\\Security\\Core\\Authorization\\AuthorizationCheckerInterface", "isGranted")
5358
.match();
5459

src/fr/adrienbrault/idea/symfony2plugin/templating/variable/resolver/FormFieldResolver.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010
import fr.adrienbrault.idea.symfony2plugin.templating.variable.TwigTypeContainer;
1111
import fr.adrienbrault.idea.symfony2plugin.templating.variable.dict.PsiVariable;
1212
import fr.adrienbrault.idea.symfony2plugin.templating.variable.resolver.holder.FormDataHolder;
13+
import fr.adrienbrault.idea.symfony2plugin.util.MethodMatcher;
1314
import fr.adrienbrault.idea.symfony2plugin.util.PhpElementsUtil;
1415
import fr.adrienbrault.idea.symfony2plugin.util.PsiElementUtils;
16+
import org.jetbrains.annotations.NotNull;
1517
import org.jetbrains.annotations.Nullable;
1618

1719
import java.util.ArrayList;
@@ -78,8 +80,8 @@ public void resolve(Collection<TwigTypeContainer> targets, Collection<TwigTypeCo
7880
}
7981
}
8082

81-
private static void attachFormFields(@Nullable MethodReference methodReference, Collection<TwigTypeContainer> targets) {
82-
if(methodReference != null && PhpElementsUtil.isMethodReferenceInstanceOf(methodReference, "\\Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller", "createForm")) {
83+
private static void attachFormFields(@Nullable MethodReference methodReference, @NotNull Collection<TwigTypeContainer> targets) {
84+
if(methodReference != null && PhpElementsUtil.isMethodReferenceInstanceOf(methodReference, new MethodMatcher.CallToSignature("\\Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller", "createForm"), new MethodMatcher.CallToSignature("\\Symfony\\Bundle\\FrameworkBundle\\Controller\\ControllerTrait", "createForm"))) {
8385
PsiElement formType = PsiElementUtils.getMethodParameterPsiElementAt(methodReference, 0);
8486
if(formType != null) {
8587
PhpClass phpClass = FormUtil.getFormTypeClassOnParameter(formType);

0 commit comments

Comments
 (0)