You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a situation in API Platform, in which I want to decorate the api_platform.jsonld.normalizer.item and api_platform.hal.normalizer.item with the same decorator. In short, that decorator adds a property to the normalized item.
In #45834, in addition to the configuration of a decorator in the service definition, it's made possible to do this using a PHP attribute #[AsDecorator]. Unfortunately, it's not possible to repeat this attribute.
I've done a quick test making the attribute repeatable, but this results in the decorator applied to the first service being overwritten by the second one, I think because of the same reason as described here: the name of the decorating service is reused. Therefore, this feature requires more work than just making the attribute repeatable: generating (or demanding configuration) unique service names is required.
Autoconfiguration features are about configuring the registered service, not creating new ones by duplicating it under a different id. So we cannot automatically register cloned definitions of the service to decorate multiple services (and trying to do that might cause issues in other layers, by registering those alternative definitions much later in the processing)
A single service can not, but a single class can be used to instantiate multiple decorating services, isn't it? It looks like that is the way it works when I follow the API Platform documentation.
Description
I have a situation in API Platform, in which I want to decorate the
api_platform.jsonld.normalizer.item
andapi_platform.hal.normalizer.item
with the same decorator. In short, that decorator adds a property to the normalized item.In #45834, in addition to the configuration of a decorator in the service definition, it's made possible to do this using a PHP attribute
#[AsDecorator]
. Unfortunately, it's not possible to repeat this attribute.I've done a quick test making the attribute repeatable, but this results in the decorator applied to the first service being overwritten by the second one, I think because of the same reason as described here: the name of the decorating service is reused. Therefore, this feature requires more work than just making the attribute repeatable: generating (or demanding configuration) unique service names is required.
Example
The text was updated successfully, but these errors were encountered: