23
23
import fr .adrienbrault .idea .symfony2plugin .templating .variable .TwigFileVariableCollector ;
24
24
import fr .adrienbrault .idea .symfony2plugin .templating .variable .TwigFileVariableCollectorParameter ;
25
25
import fr .adrienbrault .idea .symfony2plugin .templating .variable .TwigTypeContainer ;
26
+ import fr .adrienbrault .idea .symfony2plugin .templating .variable .collector .StaticVariableCollector ;
26
27
import fr .adrienbrault .idea .symfony2plugin .templating .variable .dict .PsiVariable ;
27
28
import fr .adrienbrault .idea .symfony2plugin .templating .variable .resolver .FormFieldResolver ;
28
29
import fr .adrienbrault .idea .symfony2plugin .templating .variable .resolver .FormVarsResolver ;
34
35
import org .jetbrains .annotations .NotNull ;
35
36
36
37
import java .util .*;
37
- import java .util .function .BiConsumer ;
38
38
import java .util .regex .Matcher ;
39
39
import java .util .regex .Pattern ;
40
40
import java .util .stream .Collectors ;
@@ -442,10 +442,18 @@ private static Collection<TwigTypeContainer> resolveTwigMethodName(Collection<Tw
442
442
if (phpNamedElement .getPhpNamedElement () != null ) {
443
443
for (PhpNamedElement target : getTwigPhpNameTargets (phpNamedElement .getPhpNamedElement (), typeName )) {
444
444
PhpType phpType = target .getType ();
445
- for (String typeString : phpType .getTypes ()) {
446
- PhpNamedElement phpNamedElement1 = PhpElementsUtil .getClassInterface (phpNamedElement .getPhpNamedElement ().getProject (), typeString );
447
- if (phpNamedElement1 != null ) {
448
- phpNamedElements .add (new TwigTypeContainer (phpNamedElement1 ));
445
+
446
+ // @TODO: provide extension
447
+ // custom resolving for Twig here: "app.user" => can also be a general solution just support the "getToken()->getUser()"
448
+ if (target instanceof Method && StaticVariableCollector .isUserMethod ((Method ) target )) {
449
+ phpNamedElements .addAll (getApplicationUserImplementations (target .getProject ()));
450
+ }
451
+
452
+ // @TODO: use full resolving for object, that would allow using TypeProviders and core PhpStorm feature
453
+ for (String typeString : phpType .filterPrimitives ().getTypes ()) {
454
+ PhpClass phpClass = PhpElementsUtil .getClassInterface (phpNamedElement .getPhpNamedElement ().getProject (), typeString );
455
+ if (phpClass != null ) {
456
+ phpNamedElements .add (new TwigTypeContainer (phpClass ));
449
457
}
450
458
}
451
459
}
@@ -460,6 +468,19 @@ private static Collection<TwigTypeContainer> resolveTwigMethodName(Collection<Tw
460
468
return phpNamedElements ;
461
469
}
462
470
471
+ /**
472
+ * Get possible suitable UserInterface implementation from the application scope
473
+ */
474
+ @ NotNull
475
+ private static Collection <TwigTypeContainer > getApplicationUserImplementations (@ NotNull Project project ) {
476
+ return PhpIndex .getInstance (project )
477
+ .getAllSubclasses ("\\ Symfony\\ Component\\ Security\\ Core\\ User\\ UserInterface" )
478
+ .stream ()
479
+ .filter (phpClass -> !phpClass .isInterface ()) // filter out implementation like AdvancedUserInterface
480
+ .map (TwigTypeContainer ::new )
481
+ .collect (Collectors .toList ());
482
+ }
483
+
463
484
private static Set <String > resolveTwigMethodName (Project project , Collection <String > previousElement , String typeName ) {
464
485
465
486
Set <String > types = new HashSet <>();
0 commit comments