Skip to content

Commit aa105bc

Browse files
authored
Merge pull request #1405 from Haehnchen/feature/1401-controller
Support shortcuts instances of "Symfony\Bundle\FrameworkBundle\Controller\AbstractController" #1401
2 parents a2e058f + 6dffa26 commit aa105bc

File tree

7 files changed

+37
-2
lines changed

7 files changed

+37
-2
lines changed

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

+9
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ public class SymfonyPhpReferenceContributor extends PsiReferenceContributor {
3131
new MethodMatcher.CallToSignature("\\Symfony\\Bundle\\FrameworkBundle\\Controller\\ControllerTrait", "get"),
3232
new MethodMatcher.CallToSignature("\\Symfony\\Bundle\\FrameworkBundle\\Controller\\ControllerTrait", "has"),
3333

34+
// Symfony 4
35+
new MethodMatcher.CallToSignature("\\Symfony\\Bundle\\FrameworkBundle\\Controller\\AbstractController", "get"),
36+
new MethodMatcher.CallToSignature("\\Symfony\\Bundle\\FrameworkBundle\\Controller\\AbstractController", "has"),
37+
3438
new MethodMatcher.CallToSignature("\\Symfony\\Component\\DependencyInjection\\ContainerInterface", "get"),
3539
new MethodMatcher.CallToSignature("\\Symfony\\Component\\DependencyInjection\\ContainerInterface", "has"),
3640
new MethodMatcher.CallToSignature("\\Psr\\Container\\ContainerInterface", "get"),
@@ -70,6 +74,11 @@ public class SymfonyPhpReferenceContributor extends PsiReferenceContributor {
7074
new MethodMatcher.CallToSignature("\\Symfony\\Bundle\\FrameworkBundle\\Controller\\ControllerTrait", "renderView"),
7175
new MethodMatcher.CallToSignature("\\Symfony\\Bundle\\FrameworkBundle\\Controller\\ControllerTrait", "stream"),
7276

77+
// Symfony 4
78+
new MethodMatcher.CallToSignature("\\Symfony\\Bundle\\FrameworkBundle\\Controller\\AbstractController", "render"),
79+
new MethodMatcher.CallToSignature("\\Symfony\\Bundle\\FrameworkBundle\\Controller\\AbstractController", "stream"),
80+
new MethodMatcher.CallToSignature("\\Symfony\\Bundle\\FrameworkBundle\\Controller\\AbstractController", "renderView"),
81+
7382
new MethodMatcher.CallToSignature("\\Twig_Environment", "render"),
7483
new MethodMatcher.CallToSignature("\\Twig_Environment", "loadTemplate"),
7584
new MethodMatcher.CallToSignature("\\Twig_Environment", "getTemplateClass"),

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

+3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ public void registerReferenceProviders(@NotNull PsiReferenceRegistrar psiReferen
3131

3232
// Symfony 3.3 / 3.4
3333
.addCall("\\Symfony\\Bundle\\FrameworkBundle\\Controller\\ControllerTrait", "has")
34+
35+
// Symfony 4
36+
.addCall("\\Symfony\\Bundle\\FrameworkBundle\\Controller\\AbstractController", "has")
3437
);
3538

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

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

+3
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ public class ServiceContainerUtil {
5050

5151
// Symfony 3.3 / 3.4
5252
new MethodMatcher.CallToSignature("\\Symfony\\Bundle\\FrameworkBundle\\Controller\\ControllerTrait", "get"),
53+
54+
// Symfony 4
55+
new MethodMatcher.CallToSignature("\\Symfony\\Bundle\\FrameworkBundle\\Controller\\AbstractController", "get"),
5356
};
5457

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

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

+3
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ public void register(@NotNull GotoCompletionRegistrarParameter registrar) {
9999
// Symfony 3.3 / 3.4
100100
.withSignature("\\Symfony\\Bundle\\FrameworkBundle\\Controller\\ControllerTrait", "createForm")
101101

102+
// Symfony 4
103+
.withSignature("\\Symfony\\Bundle\\FrameworkBundle\\Controller\\AbstractController", "createForm")
104+
102105
.withSignature("\\Symfony\\Component\\Form\\FormFactoryInterface", "create")
103106
.withSignature("\\Symfony\\Component\\Form\\FormFactory", "createBuilder")
104107
.match();

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

+8-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ public class PhpRouteReferenceContributor extends PsiReferenceContributor {
2525
new MethodMatcher.CallToSignature("\\Symfony\\Bundle\\FrameworkBundle\\Controller\\ControllerTrait", "generateUrl"),
2626
new MethodMatcher.CallToSignature("\\Symfony\\Bundle\\FrameworkBundle\\Controller\\ControllerTrait", "redirectToRoute"),
2727

28+
// Symfony 4
29+
new MethodMatcher.CallToSignature("\\Symfony\\Bundle\\FrameworkBundle\\Controller\\AbstractController", "generateUrl"),
30+
new MethodMatcher.CallToSignature("\\Symfony\\Bundle\\FrameworkBundle\\Controller\\AbstractController", "redirectToRoute"),
31+
2832
new MethodMatcher.CallToSignature("\\Symfony\\Component\\Routing\\Generator\\UrlGeneratorInterface", "generate"),
2933

3034
};
@@ -33,7 +37,10 @@ public class PhpRouteReferenceContributor extends PsiReferenceContributor {
3337
new MethodMatcher.CallToSignature("\\Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller", "forward"),
3438

3539
// Symfony 3.3 / 3.4
36-
new MethodMatcher.CallToSignature("\\Symfony\\Bundle\\FrameworkBundle\\Controller\\ControllerTrait", "forward")
40+
new MethodMatcher.CallToSignature("\\Symfony\\Bundle\\FrameworkBundle\\Controller\\ControllerTrait", "forward"),
41+
42+
// Symfony 4
43+
new MethodMatcher.CallToSignature("\\Symfony\\Bundle\\FrameworkBundle\\Controller\\AbstractController", "forward"),
3744
};
3845

3946
@Override

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

+5
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ public void register(@NotNull GotoCompletionRegistrarParameter registrar) {
6262
MethodMatcher.MethodMatchParameter arrayMatchParameter = new MethodMatcher.ArrayParameterMatcher(context, 0)
6363
.withSignature("Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller", "isGranted")
6464
.withSignature("Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller", "denyAccessUnlessGranted")
65+
66+
// Symfony 4
67+
.withSignature("Symfony\\Bundle\\FrameworkBundle\\Controller\\AbstractController", "isGranted")
68+
.withSignature("Symfony\\Bundle\\FrameworkBundle\\Controller\\AbstractController", "denyAccessUnlessGranted")
69+
6570
.withSignature("Symfony\\Component\\Security\\Core\\Authorization\\AuthorizationCheckerInterface", "isGranted")
6671
.match();
6772

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

+6-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,12 @@ public void resolve(Collection<TwigTypeContainer> targets, Collection<TwigTypeCo
8181
}
8282

8383
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"))) {
84+
if(methodReference != null && PhpElementsUtil.isMethodReferenceInstanceOf(
85+
methodReference,
86+
new MethodMatcher.CallToSignature("\\Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller", "createForm"),
87+
new MethodMatcher.CallToSignature("\\Symfony\\Bundle\\FrameworkBundle\\Controller\\ControllerTrait", "createForm"),
88+
new MethodMatcher.CallToSignature("\\Symfony\\Bundle\\FrameworkBundle\\Controller\\AbstractController", "createForm")
89+
)) {
8590
PsiElement formType = PsiElementUtils.getMethodParameterPsiElementAt(methodReference, 0);
8691
if(formType != null) {
8792
PhpClass phpClass = FormUtil.getFormTypeClassOnParameter(formType);

0 commit comments

Comments
 (0)