@@ -53,10 +53,9 @@ Symfony ships with five value resolvers in the HttpKernel component:
5353Adding a Custom Value Resolver
5454------------------------------
5555
56- Adding a new value resolver requires creating one class and one service
57- definition. In the next example, you'll create a value resolver to inject the
58- ``User `` object from the security system. Given you write the following
59- controller::
56+ In the next example, you'll create a value resolver to inject the object that
57+ represents the current user whenever a controller method type-hints an argument
58+ with the ``User `` class::
6059
6160 namespace AppBundle\Controller;
6261
@@ -71,10 +70,30 @@ controller::
7170 }
7271 }
7372
74- Somehow you will have to get the ``User `` object and inject it into the controller.
75- This can be done by implementing the
76- :class: `Symfony\\ Component\\ HttpKernel\\ Controller\\ ArgumentValueResolverInterface `.
77- This interface specifies that you have to implement two methods:
73+ Beware that this feature is already provided by the `@ParamConverter `_
74+ annotation from the SensioFrameworkExtraBundle. If you have that bundle
75+ installed in your project, add this config to disable the auto-conversion of
76+ type-hinted method arguments:
77+
78+ .. configuration-block ::
79+
80+ .. code-block :: yaml
81+
82+ # app/config/config.yml
83+ sensio_framework_extra :
84+ request :
85+ converters : true
86+ auto_convert : false
87+
88+ .. code-block :: xml
89+
90+ <sensio-framework-extra : config >
91+ <request converters =" true" auto-convert =" true" />
92+ </sensio-framework-extra : config >
93+
94+ Adding a new value resolver requires creating a class that implements
95+ :class: `Symfony\\ Component\\ HttpKernel\\ Controller\\ ArgumentValueResolverInterface `
96+ and defining a service for it. The interface defines two methods:
7897
7998``supports() ``
8099 This method is used to check whether the value resolver supports the
@@ -201,4 +220,5 @@ subrequests.
201220 $user = null ``). The ``DefaultValueResolver `` is executed as the last
202221 resolver and will use the default value if no value was already resolved.
203222
223+ .. _`@ParamConverter` : https://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/converters.html
204224.. _`yield` : http://php.net/manual/en/language.generators.syntax.php
0 commit comments