Skip to content

Commit

Permalink
Merge pull request #2219 from Haehnchen/feature/template-mail
Browse files Browse the repository at this point in the history
whitelist htmlTemplate / textTemplate to be valid Twig entrypoint
  • Loading branch information
Haehnchen authored Aug 31, 2023
2 parents d43006a + a113ad8 commit 690da58
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ public class SymfonyPhpReferenceContributor extends PsiReferenceContributor {
new MethodMatcher.CallToSignature("\\Twig\\Environment", "display"),
new MethodMatcher.CallToSignature("\\Twig\\Environment", "isTemplateFresh"),
new MethodMatcher.CallToSignature("\\Twig\\Environment", "resolveTemplate"), // @TODO: also "is_array($names)"

new MethodMatcher.CallToSignature("\\Symfony\\Bridge\\Twig\\Mime\\TemplatedEmail", "htmlTemplate"),
new MethodMatcher.CallToSignature("\\Symfony\\Bridge\\Twig\\Mime\\TemplatedEmail", "textTemplate"),
};

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.function.Consumer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Stream;

import static fr.adrienbrault.idea.symfony2plugin.util.StringUtils.underscore;

Expand Down Expand Up @@ -310,7 +311,7 @@ public static void processMethodReference(@NotNull MethodReference methodReferen
return;
}

if(!methods.get().contains(methodName) && !methodName.toLowerCase().contains("render")) {
if (!methods.get().contains(methodName) && Stream.of("render", "htmltemplate", "texttemplate").noneMatch(s -> methodName.toLowerCase().contains(s))) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ public void testThatTwigRenderMethodsAreInIndex() {
" $foo->render($this->foo);\n" +
" $foo->render(\\DateTime::foo);\n" +
" $foo->renderView($defaultParameter);\n" +
" $foo1->htmlTemplate('emails/signup.html.twig');\n" +
" $foo1->textTemplate('emails/signup.txt.twig');\n" +
" }\n" +
"}" +
"" +
"\n" +
"function foobarFunc()" +
"{\n" +
" $foo->render('foo-render.html.twig')\n" +
Expand All @@ -50,7 +52,7 @@ public void testThatTwigRenderMethodsAreInIndex() {
"foo-render.html.twig", "foo-renderView.html.twig", "foo-renderResponse.html.twig",
"@Foo/overwrite.html.twig", "const.html.twig", "var.html.twig", "private.html.twig", "foobar-render.twig",
"foo-render-ternary.html.twig", "const-ternary.html.twig", "foo-render-coalesce.html.twig", "const-coalesce.html.twig",
"foo-var-assignment-expression.html.twig", "default-function-parameter.html.twig"
"foo-var-assignment-expression.html.twig", "default-function-parameter.html.twig", "emails/signup.html.twig", "emails/signup.txt.twig"
);

assertIndexContainsKeyWithValue(PhpTwigTemplateUsageStubIndex.KEY, "foo-render.html.twig", value ->
Expand Down

0 comments on commit 690da58

Please sign in to comment.