Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#2261 whitelist "Symfony\Bridge\Twig\Attribute\Template" for template usages to fix render detection #2351

Merged
merged 1 commit into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void visitElement(@NotNull PsiElement element) {

if (element instanceof PhpAttribute) {
String fqn = ((PhpAttribute) element).getFQN();
if (fqn != null && PhpElementsUtil.isInstanceOf(element.getProject(), fqn, TwigUtil.TEMPLATE_ANNOTATION_CLASS)) {
if (fqn != null && Arrays.stream(TwigUtil.TEMPLATE_ANNOTATION_CLASS).anyMatch(s -> PhpElementsUtil.isInstanceOf(element.getProject(), fqn, s))) {
annotate((PhpAttribute) element, holder);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,17 +269,19 @@ public boolean processPhpCallInstruction(PhpCallInstruction instruction) {

public static class TemplateRenderVisitor {
public static void processMethodAttributes(@NotNull Method method, Consumer<Triple<String, PhpNamedElement, FunctionReference>> consumer) {
Collection<@NotNull PhpAttribute> attributes = method.getAttributes(TwigUtil.TEMPLATE_ANNOTATION_CLASS);
for (PhpAttribute attribute : attributes) {
if (attribute.getArguments().isEmpty()) {
// #[@Template()]
visitMethodForGuessing(method, consumer);
} else {
// [@Template("foobar.html.twig")]
// #[@Template(template: "foobar.html.twig")]
String template = PhpPsiAttributesUtil.getAttributeValueByNameAsStringWithDefaultParameterFallback(attribute, "template");
if (StringUtils.isNotBlank(template)) {
addTemplateWithScope(template, method, null, consumer);
for (String templateAnnotationClass : TwigUtil.TEMPLATE_ANNOTATION_CLASS) {
Collection<@NotNull PhpAttribute> attributes = method.getAttributes(templateAnnotationClass);
for (PhpAttribute attribute : attributes) {
if (attribute.getArguments().isEmpty()) {
// #[@Template()]
visitMethodForGuessing(method, consumer);
} else {
// [@Template("foobar.html.twig")]
// #[@Template(template: "foobar.html.twig")]
String template = PhpPsiAttributesUtil.getAttributeValueByNameAsStringWithDefaultParameterFallback(attribute, "template");
if (StringUtils.isNotBlank(template)) {
addTemplateWithScope(template, method, null, consumer);
}
}
}
}
Expand Down Expand Up @@ -414,7 +416,7 @@ public static void processDocTag(@NotNull PhpDocTag phpDocTag, Consumer<Triple<S
}

String annotationFqnName = AnnotationBackportUtil.getClassNameReference(phpDocTag, fileImports);
if(!StringUtils.stripStart(TwigUtil.TEMPLATE_ANNOTATION_CLASS, "\\").equals(StringUtils.stripStart(annotationFqnName, "\\"))) {
if (Arrays.stream(TwigUtil.TEMPLATE_ANNOTATION_CLASS).noneMatch(s -> s.equals(annotationFqnName))) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,10 @@ public enum NamespaceType {

public static final String[] IMG_FILES_EXTENSIONS = new String[] { "png", "jpg", "jpeg", "gif", "svg"};

public static final String TEMPLATE_ANNOTATION_CLASS = "\\Sensio\\Bundle\\FrameworkExtraBundle\\Configuration\\Template";
public static final String[] TEMPLATE_ANNOTATION_CLASS = new String[] {
"\\Sensio\\Bundle\\FrameworkExtraBundle\\Configuration\\Template",
"\\Symfony\\Bridge\\Twig\\Attribute\\Template",
};

public static class TwigPathNamespaceComparator implements Comparator<TwigPath> {
@Override
Expand Down
Loading