I'm using Symfony 6.2 with php 8.1.
Since the update of SF 6.2 i had to remove SensioFrameworkExtraBundle
and migrate my code from ParamConverter
to new custom ValueResolver
.
However, i'm facing a lack a feature from this migration or i miss something :(
With a custom ParamConverter
, i could resolve a parameter and rewrite the new content in the Request
. This allow me to chain any ParamConverter
.
The new way with custom ValueResolver
does not rewrite the content in the Request.
Of course i can force to rewrite the content or create a new attribute in the Request
but i feel it's wrong or not proper way.
My use case :
The resolver for TranslationKey need the resolver result of TranslationDomain and TranslationLanguage. basically i would like to chain these resolver or group them like we can do in form Constraint.
services.yaml
App\Service\\ranslation\Request\ValueResolver\TranslationLanguageValueResolver:
tags:
- { name: controller.argument_value_resolver, priority: 103 }
App\Service\Translation\Request\ValueResolver\\TranslationDomainValueResolver:
tags:
- { name: controller.argument_value_resolver, priority: 102 }
App\Service\Translation\Request\ValueResolver\TranslationKeyValueResolver:
tags:
- { name: controller.argument_value_resolver, priority: 101 }
My controller :
public function edit (Request $request,
TranslationLanguage $translationLanguage,
TranslationDomain $translationDomain,
TranslationKey $translationKey,
TranslationHelper $translationHelper,
Translation $translation): Response
{
[some code]
}
TranslationKeyValueResolver :
public function resolve (Request $request, ArgumentMetadata $argument): iterable
{
$argumentType = $argument->getType();
if (!$argumentType || !($argumentType === TranslationKey::class)) {
return [];
}
$translationLanguage = $request->get('translationLanguage'); //=> does not return the object since it's not chained
[some code]
return [new TranslationKey($translationKey)];
}
Before :
public function apply(Request $request, ParamConverter $configuration)
{
[some code]
$request->attributes->set($configuration->getName(), new TranslationLanguage($languages));
return true;
}
After :
public function resolve (Request $request, ArgumentMetadata $argument): iterable
{
$argumentType = $argument->getType();
if (!$argumentType || !($argumentType === TranslationLanguage::class)) {
return [];
}
[some code]
return [new TranslationLanguage($languages)];
}
So, i tried to create a new attribute in Request with the new value, but it feel terribly wrong since it suppose all resolver has been executed before and in order. But it's working.
I though to revolve again TranslationLangage and TranslationDomain in TranslationKeyValueResolver but i don't know how, neither what tag i should set in that case ? Custom tag ?
App\Service\Translation\Request\ValueResolver\TranslationKeyValueResolver:
tags:
- { name: controller.argument_value_resolver, priority: 101 }
- { name: another_tag_to_resolve_argument_from_resolver, priority: 101 } ??
Any idea please ?
Radyium Thanks