SensioFrameworkExtraBundle icon indicating copy to clipboard operation
SensioFrameworkExtraBundle copied to clipboard

Naming ParamConverter with autowiring activated and with no priority set

Open loverg-c opened this issue 5 years ago • 4 comments

Hello,

I'm trying to call my CustomParamConverter from my Controller.

If I understand how converters work: if I don't explicitly write the converter= options in the @ParamConverter annotation it will call ALL converters by priority.

Problem is if I want to typed my controller's param with an Entity class, then it will call the DoctrineParamConverter

So, I have to declare explicitly my converter in my services.yml, give it a name (like my_converter) and then call the @ParamConverter annotation with the converter="my_converter" options.

Is there another way to give a name to my CustomParamConverter and using autowiring ? Because when I don't declare it explicitly, the converter name seems to be NULL in the AddParamConverterPass class :/

Maybe we could add a getName method in the paramConverterInterface ?

loverg-c avatar Jun 27 '19 15:06 loverg-c

Ok I just understand that I should use DTO/Value object with param converter (instead of entity itself) if I don't want to use database and don't want to specify the paramConverter

But my question about naming the paramConverter is still available ^^'

loverg-c avatar Jun 28 '19 09:06 loverg-c

I think adding a getName function could be a great solution

VincentLanglet avatar Aug 28 '19 10:08 VincentLanglet

Same here. Custom param conventer has null name when autowiring and therefore it is not picked up due to exception "No converter named 'bar' found for conversion of parameter 'foo'"

GinoPane avatar Mar 25 '20 19:03 GinoPane

Yes or auto set the name to something like the class name or the FQCN. It's currently driving me a bit crazy 😆

gaetan-petit avatar Apr 17 '20 13:04 gaetan-petit