[LiveComponent] add controller tag and default metadata values for all service declaration types
| Q | A |
|---|---|
| Bug fix? | no |
| New feature? | yes |
| Deprecations? | no |
| Documentation? | no |
| License | MIT |
In my project I don't use attributes like #[AsLiveComponent] in order to declare services and live components but I use yaml files (not my choice).
It works fine for all my services but live components are not well supported because we have to add extra parameters.
With #[AsLiveComponent] attribute, we have default values for :
- the route metadata :
'ux_live_component' - and the url reference type metadata
UrlGeneratorInterface::ABSOLUTE_PATH
We also add controller.service_arguments tag in LiveComponentExtension class.
But if we don't use this attribute and we want to use another type of service declaration, we have to add all these information :
services:
MyServiceClass:
tags:
-
name: twig.component
live: true
route: ux_live_component
url_reference_type: 1
-
name: controller.service_arguments
If we do not, we have errors likes theses :
An exception has been thrown during the rendering of a template ("Symfony\Component\Routing\Router::generate(): Argument #1 ($name) must be of type string, null given, called in /app/vendor/symfony/ux-live-component/src/Util/LiveControllerAttributesCreator.php on line 63")
An exception has been thrown during the rendering of a template ("Symfony\Component\Routing\Router::generate(): Argument #3 ($referenceType) must be of type int, null given, called in /app/vendor/symfony/ux-live-component/src/Util/LiveControllerAttributesCreator.php on line 63")
The controller for URI "/_components/my_customer_live_component" is not callable: Controller "MyCustomLiveComponentClass" cannot be fetched from the container because it is private. Did you forget to tag the service with "controller.service_arguments"?
These errors do not exist for php attribute declaration so I made this PR to have the same behavior regardless of how the live component is declared
Hi,
For the same reasons explained in https://github.com/symfony/ux/pull/3064, I'm :-1: here. The tag is purely internal and not documented, I don't think we want to encourage users to rely on it.
In my project I don't use attributes like #[AsLiveComponent] in order to declare services and live components but I use yaml files (not my choice).
Why? Because of "DDD"?
Hi @Kocal ,
Why? Because of "DDD"?
We use DDD but it's not the reason. We could accept to use attributes in the infrastructure layer but we do not use autowiring and autoconfigure features (my client's rules).
And since this service declaration is still possible, I find it unfortunate that it cannot be used without exposing internal properties as I demonstrate.