@@ -382,9 +382,9 @@ public boolean accepts(@NotNull FunctionReference functionReference, ProcessingC
382
382
.withLanguage (PhpLanguage .INSTANCE );
383
383
}
384
384
385
- private static final PatternCondition <StringLiteralExpression > EMPTY_PREVIOUS_LEAF = new PatternCondition <>("previous leaf empty" ) {
385
+ private static final PatternCondition <PsiElement > EMPTY_PREVIOUS_LEAF = new PatternCondition <>("previous leaf empty" ) {
386
386
@ Override
387
- public boolean accepts (@ NotNull StringLiteralExpression stringLiteralExpression , ProcessingContext context ) {
387
+ public boolean accepts (@ NotNull PsiElement stringLiteralExpression , ProcessingContext context ) {
388
388
return stringLiteralExpression .getPrevSibling () == null ;
389
389
}
390
390
};
@@ -408,6 +408,26 @@ public static PsiElementPattern.Capture<PsiElement> getFirstAttributeStringPatte
408
408
);
409
409
}
410
410
411
+ /**
412
+ * #[Security("is_granted(['POST_SHOW'])")]
413
+ */
414
+ @ NotNull
415
+ public static PsiElementPattern .Capture <PsiElement > getFirstAttributeArrayStringPattern (@ NotNull String clazz ) {
416
+ return PlatformPatterns .psiElement ().withElementType (PlatformPatterns .elementType ().or (
417
+ PhpTokenTypes .STRING_LITERAL_SINGLE_QUOTE ,
418
+ PhpTokenTypes .STRING_LITERAL
419
+ ))
420
+ .withParent (PlatformPatterns .psiElement (StringLiteralExpression .class )
421
+ .withParent (PlatformPatterns .psiElement (PhpElementTypes .ARRAY_VALUE ).withParent (
422
+ PlatformPatterns .psiElement (ArrayCreationExpression .class ).with (EMPTY_PREVIOUS_LEAF ).withParent (PlatformPatterns .psiElement (ParameterList .class )
423
+ .withParent (PlatformPatterns .psiElement (PhpAttribute .class )
424
+ .with (new AttributeInstancePatternCondition (clazz ))
425
+ )
426
+ )
427
+ ))
428
+ );
429
+ }
430
+
411
431
/**
412
432
* #[Security(foobar: "is_granted('POST_SHOW')")]
413
433
*/
@@ -433,6 +453,33 @@ public static PsiElementPattern.Capture<PsiElement> getAttributeNamedArgumentStr
433
453
);
434
454
}
435
455
456
+ /**
457
+ * #[Security(tags: ['foobar']])]
458
+ */
459
+ @ NotNull
460
+ public static PsiElementPattern .Capture <PsiElement > getAttributeNamedArgumentArrayStringPattern (@ NotNull String clazz , @ NotNull String namedArgument ) {
461
+ return PlatformPatterns .psiElement ().withElementType (PlatformPatterns .elementType ().or (
462
+ PhpTokenTypes .STRING_LITERAL_SINGLE_QUOTE ,
463
+ PhpTokenTypes .STRING_LITERAL
464
+ ))
465
+ .withParent (PlatformPatterns .psiElement (StringLiteralExpression .class )
466
+ .withParent (PlatformPatterns .psiElement (PhpElementTypes .ARRAY_VALUE ).withParent (
467
+ PlatformPatterns .psiElement (ArrayCreationExpression .class ).afterLeafSkipping (
468
+ PlatformPatterns .psiElement (PsiWhiteSpace .class ),
469
+ PlatformPatterns .psiElement (PhpTokenTypes .opCOLON ).afterLeafSkipping (
470
+ PlatformPatterns .psiElement (PsiWhiteSpace .class ),
471
+ PlatformPatterns .psiElement (PhpTokenTypes .IDENTIFIER ).withText (namedArgument )
472
+ )
473
+ )
474
+ .withParent (PlatformPatterns .psiElement (ParameterList .class )
475
+ .withParent (PlatformPatterns .psiElement (PhpAttribute .class )
476
+ .with (new AttributeInstancePatternCondition (clazz ))
477
+ )
478
+ )
479
+ ))
480
+ );
481
+ }
482
+
436
483
/**
437
484
* Check if given Attribute
438
485
*/
0 commit comments