-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DependencyInjection] Attribute : Decorator + Autoconfigure does not work #49931
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
Comments
Hi @lyrixx, I've taken a look into the issue and was able to recreate it on v6.2 using your example within a test case. It looks like some code was added in v4.2 specifically to prevent auto-configured tags from being added to service decorators for specific reasons: symfony/src/Symfony/Component/DependencyInjection/Compiler/ResolveInstanceofConditionalsPass.php Line 126 in 746c06b
See Issue #30391 and PR #30417 It looks like one current solution is to add the |
…l decorator (HypeMC) This PR was merged into the 5.4 branch. Discussion ---------- [DependencyInjection] Don't ignore attributes on the actual decorator | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #49931 | License | MIT | Doc PR | - An attempt to fix #49931 without reintroducing the problem reported in #30391 and fixed by #30417. The idea here is that if the attribute is declared on the decorator itself, it shouldn't be ignored as it was explicitly added. Commits ------- fdd2ec2 [DependencyInjection] Don't ignore attributes on the actual decorator
Hello, Unfortunately, It still does not work as expected. I have another exemple: use Symfony\Component\Config\Loader\Loader;
#[Autoconfigure(tags: ['routing.loader'])]
#[AsDecorator('api_platform.route_loader')]
class RouteLoader extends Loader
{
private const DOC_ROUTES = [
'api_entrypoint',
'api_doc',
];
public function __construct(
private readonly VisibilityDecider $visibilityDecider,
private readonly ApiLoader $decorated,
#[Autowire('%redirectionio.api_host%')]
private readonly string $publicHost,
#[Autowire('%redirectionio.frontend_host%')]
private readonly string $privateHost,
) {
} When I look at the container.xml: <service id="AppBundle\Api\Routing\RouteLoader" class="AppBundle\Api\Routing\RouteLoader" autowire="true" autoconfigure="true">
<tag name="monolog.logger" channel="api"/>
<argument type="service" id="AppBundle\Api\VisibilityDecider"/>
<argument type="service" id="api_platform.route_loader.legacy"/>
<argument>api.redirection-io.test</argument>
<argument>redirection-io.test</argument>
</service> I miss the |
Note: If I add the tag from the YAML, it do works. So it should work via an attributes at some point! |
@lyrixx I'm having trouble reproducing the problem, here's what I get: <service id="App\Loader\RouteLoader" class="App\Loader\RouteLoader" autowire="true" autoconfigure="true">
<tag name="routing.loader"/>
<argument type="service" id="App\Loader\RouteLoader.inner"/>
</service> and here's my example application: example-application.zip. Not sure what I'm doing differently. |
Hello, I stumbled on this issue when trying to use attributes to decorate router and had no way to make it being called 😭 I also created a reproducer on https://github.com/kissifrot/sf-attribute-decorator-bug using 2 different services which should both be called (sf 6.4.3 is being used) Same as @lyrixx , when using YAML, no issue, but nothing with attributes |
This comment was marked as outdated.
This comment was marked as outdated.
@kissifrot Ignore my last response, I was wrong. I've double-checked and the reason the attribute is not working is because you are decorating a different service than in YAML. In YAML, you are decorating the -#[AsDecorator(decorates: RouterInterface::class, priority: 500)]
+#[AsDecorator(decorates: 'router', priority: 500)]
class DecoratingUsingAttributesUrlGenerator implements RouterInterface
{ The core problem here is that you have two different aliases: Since Symfony internally uses |
I'm not sure if this is even a bug tbh, since you are decorating two different aliases. Maybe @nicolas-grekas can shed some light on this? |
Just checked again, and it seems to work 🎉 |
Symfony version(s) affected
6.2 at least
Description
If we use both attribute, it does not work: the service is not tagged.
Trace
ReflectionException:
Trying to invoke abstract method App\Jerome\JeromeInterface::getNameStoredInDb()
at /home/gregoire/dev/labs/symfony/repro-dic-locator-factory/vendor/symfony/dependency-injection/Compiler/PriorityTaggedServiceTrait.php:151
at ReflectionMethod->invoke()
(/home/gregoire/dev/labs/symfony/repro-dic-locator-factory/vendor/symfony/dependency-injection/Compiler/PriorityTaggedServiceTrait.php:151)
at Symfony\Component\DependencyInjection\Compiler\PriorityTaggedServiceUtil::getDefault()
(/home/gregoire/dev/labs/symfony/repro-dic-locator-factory/vendor/symfony/dependency-injection/Compiler/PriorityTaggedServiceTrait.php:83)
at Symfony\Component\DependencyInjection\Compiler\ServiceLocatorTagPass->findAndSortTaggedServices()
(/home/gregoire/dev/labs/symfony/repro-dic-locator-factory/vendor/symfony/dependency-injection/Compiler/ServiceLocatorTagPass.php:37)
at Symfony\Component\DependencyInjection\Compiler\ServiceLocatorTagPass->processValue()
(/home/gregoire/dev/labs/symfony/repro-dic-locator-factory/vendor/symfony/dependency-injection/Compiler/AbstractRecursivePass.php:82)
at Symfony\Component\DependencyInjection\Compiler\AbstractRecursivePass->processValue()
(/home/gregoire/dev/labs/symfony/repro-dic-locator-factory/vendor/symfony/dependency-injection/Compiler/ServiceLocatorTagPass.php:48)
at Symfony\Component\DependencyInjection\Compiler\ServiceLocatorTagPass->processValue()
(/home/gregoire/dev/labs/symfony/repro-dic-locator-factory/vendor/symfony/dependency-injection/Compiler/AbstractRecursivePass.php:91)
at Symfony\Component\DependencyInjection\Compiler\AbstractRecursivePass->processValue()
(/home/gregoire/dev/labs/symfony/repro-dic-locator-factory/vendor/symfony/dependency-injection/Compiler/ServiceLocatorTagPass.php:48)
at Symfony\Component\DependencyInjection\Compiler\ServiceLocatorTagPass->processValue()
(/home/gregoire/dev/labs/symfony/repro-dic-locator-factory/vendor/symfony/dependency-injection/Compiler/AbstractRecursivePass.php:82)
at Symfony\Component\DependencyInjection\Compiler\AbstractRecursivePass->processValue()
(/home/gregoire/dev/labs/symfony/repro-dic-locator-factory/vendor/symfony/dependency-injection/Compiler/ServiceLocatorTagPass.php:48)
at Symfony\Component\DependencyInjection\Compiler\ServiceLocatorTagPass->processValue()
(/home/gregoire/dev/labs/symfony/repro-dic-locator-factory/vendor/symfony/dependency-injection/Compiler/AbstractRecursivePass.php:47)
at Symfony\Component\DependencyInjection\Compiler\AbstractRecursivePass->process()
(/home/gregoire/dev/labs/symfony/repro-dic-locator-factory/vendor/symfony/dependency-injection/Compiler/Compiler.php:82)
at Symfony\Component\DependencyInjection\Compiler\Compiler->compile()
(/home/gregoire/dev/labs/symfony/repro-dic-locator-factory/vendor/symfony/dependency-injection/ContainerBuilder.php:757)
at Symfony\Component\DependencyInjection\ContainerBuilder->compile()
(/home/gregoire/dev/labs/symfony/repro-dic-locator-factory/vendor/symfony/http-kernel/Kernel.php:546)
at Symfony\Component\HttpKernel\Kernel->initializeContainer()
(/home/gregoire/dev/labs/symfony/repro-dic-locator-factory/vendor/symfony/http-kernel/Kernel.php:789)
at Symfony\Component\HttpKernel\Kernel->preBoot()
(/home/gregoire/dev/labs/symfony/repro-dic-locator-factory/vendor/symfony/http-kernel/Kernel.php:190)
at Symfony\Component\HttpKernel\Kernel->handle()
(/home/gregoire/dev/labs/symfony/repro-dic-locator-factory/vendor/symfony/runtime/Runner/Symfony/HttpKernelRunner.php:35)
at Symfony\Component\Runtime\Runner\Symfony\HttpKernelRunner->run()
(/home/gregoire/dev/labs/symfony/repro-dic-locator-factory/vendor/autoload_runtime.php:35)
at require_once('/home/gregoire/dev/labs/symfony/repro-dic-locator-factory/vendor/autoload_runtime.php')
(/home/gregoire/dev/labs/symfony/repro-dic-locator-factory/public/index.php:5)
How to reproduce
https://github.com/lyrixx/test/tree/sf-repro-tag-decorator
Possible Solution
No response
Additional Context
No response
The text was updated successfully, but these errors were encountered: