Skip to content

Commit 29fddd9

Browse files
authored
Merge pull request #1993 from Haehnchen/feature/1991-asdecorates-attribute
#1991 support "decorates" inside "AsDecorator" attribute
2 parents 6b8f850 + 64dc329 commit 29fddd9

File tree

4 files changed

+47
-1
lines changed

4 files changed

+47
-1
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ public class ServiceContainerUtil {
7373
public static final String AUTOWIRE_ATTRIBUTE_CLASS = "\\Symfony\\Component\\DependencyInjection\\Attribute\\Autowire";
7474
public static final String TAGGED_ITERATOR_ATTRIBUTE_CLASS = "\\Symfony\\Component\\DependencyInjection\\Attribute\\TaggedIterator";
7575
public static final String TAGGED_LOCATOR_ATTRIBUTE_CLASS = "\\Symfony\\Component\\DependencyInjection\\Attribute\\TaggedLocator";
76+
public static final String DECORATOR_ATTRIBUTE_CLASS = "\\Symfony\\Component\\DependencyInjection\\Attribute\\AsDecorator";
7677

7778
@NotNull
7879
public static Collection<ServiceSerializable> getServicesInFile(@NotNull PsiFile psiFile) {

src/main/java/fr/adrienbrault/idea/symfony2plugin/dic/registrar/DicGotoCompletionRegistrar.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,13 @@ public void register(@NotNull GotoCompletionRegistrarParameter registrar) {
113113
);
114114

115115
// #[Autowire(service: 'some_service')]
116+
// #[AsDecorator(decorates: 'some_service')]
116117
registrar.register(
117-
PhpElementsUtil.getAttributeNamedArgumentStringPattern(ServiceContainerUtil.AUTOWIRE_ATTRIBUTE_CLASS, "service"),
118+
PlatformPatterns.or(
119+
PhpElementsUtil.getAttributeNamedArgumentStringPattern(ServiceContainerUtil.AUTOWIRE_ATTRIBUTE_CLASS, "service"),
120+
PhpElementsUtil.getAttributeNamedArgumentStringPattern(ServiceContainerUtil.DECORATOR_ATTRIBUTE_CLASS, "decorates"),
121+
PhpElementsUtil.getFirstAttributeStringPattern(ServiceContainerUtil.DECORATOR_ATTRIBUTE_CLASS)
122+
),
118123
psiElement -> {
119124
PsiElement context = psiElement.getContext();
120125
if (!(context instanceof StringLiteralExpression)) {

src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/dic/registrar/DicGotoCompletionRegistrarTest.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,4 +228,34 @@ public void testServiceContributorForNamedAttribute() {
228228
PlatformPatterns.psiElement()
229229
);
230230
}
231+
232+
public void testServiceContributorDecoratesAttribute() {
233+
assertCompletionContains(PhpFileType.INSTANCE, "<?php\n" +
234+
"use Symfony\\Component\\DependencyInjection\\Attribute\\AsDecorator;\n" +
235+
"#[AsDecorator('<caret>')]\n" +
236+
"class HandlerCollection {}",
237+
"foo_bar_service"
238+
);
239+
240+
assertNavigationMatch(PhpFileType.INSTANCE, "<?php\n" +
241+
"use Symfony\\Component\\DependencyInjection\\Attribute\\AsDecorator;\n" +
242+
"#[AsDecorator(decorates: 'foo_bar<caret>_service')]\n" +
243+
"class HandlerCollection {}",
244+
PlatformPatterns.psiElement()
245+
);
246+
247+
assertCompletionContains(PhpFileType.INSTANCE, "<?php\n" +
248+
"use Symfony\\Component\\DependencyInjection\\Attribute\\AsDecorator;\n" +
249+
"#[AsDecorator(decorates: '<caret>')]\n" +
250+
"class HandlerCollection {}",
251+
"foo_bar_service"
252+
);
253+
254+
assertNavigationMatch(PhpFileType.INSTANCE, "<?php\n" +
255+
"use Symfony\\Component\\DependencyInjection\\Attribute\\AsDecorator;\n" +
256+
"#[AsDecorator(decorates: 'foo_bar<caret>_service')]\n" +
257+
"class HandlerCollection {}",
258+
PlatformPatterns.psiElement()
259+
);
260+
}
231261
}

src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/dic/registrar/fixtures/classes.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,16 @@ public function __construct(
4747
) {
4848
}
4949
}
50+
51+
class AsDecorator
52+
{
53+
public function __construct(
54+
public string $decorates,
55+
public int $priority = 0,
56+
public int $onInvalid = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE,
57+
) {
58+
}
59+
}
5060
}
5161

5262
namespace

0 commit comments

Comments
 (0)