When writing Symfony Applications we have the choice to use TypeHinting in our Controller Actions. In many cases Symfony provides "magic" parameter conversions which will examine the request and produce a model of the parameter class. This can be achieved by an
Both are using more or less the same (regarding the result). So which one should we use?
First: ArgumentResolver is the more recent implementation which comes with the latest Symfony Frameworks. For the ParamConverter we need to add a dependency from SensioLabs (the extra bundle). So, this can already be a hint for you to decide which one to use.
Second: A ParamConverter need to be explicitly added as an Attribute or Annotation to your action. ArgumentResolvers work "in the background". If you don't mind a little more boilerplate code, you can use both. Otherwise use ArgumentResolvers.
Third: ArgumentResovler, even if is now part of Symfony, do not provide the same default implementations as a ParamConverter. For instance there is a ready to use ParamConverter for Doctrine entities. This can be very helpful, especially when you are trying to go fast on a project (probably MVP).
Thank you for reading this far! Let’s connect. You can @ me on Twitter (@debilofant) with comments, or feel free to follow. Please like/share this article so that it reaches others as well.