@@ -31,6 +31,7 @@ Symfony ships with four value resolvers in the HttpKernel:
31
31
When the action is called, the last (variadic) argument will contain all the values of this array.
32
32
33
33
.. note ::
34
+
34
35
In older versions of Symfony this logic was all resolved within the ``ControllerResolver ``. The
35
36
old functionality is moved to the ``LegacyArgumentResolver ``, which contains the previously
36
37
used resolving logic.
@@ -39,7 +40,7 @@ Adding a New Value Resolver
39
40
---------------------------
40
41
41
42
Adding a new value resolver requires one class and one service defintion. In our next example, we
42
- will be creating a shortcut to inject the ``User `` object from our security. Given we write the following
43
+ will be creating a shortcut to inject the ``User `` object from our security. Given you write the following
43
44
action::
44
45
45
46
namespace AppBundle\Controller;
@@ -52,37 +53,38 @@ action::
52
53
}
53
54
}
54
55
55
- Somehow we will have to get the ``User `` object and inject it into our action. This can be done
56
+ Somehow you will have to get the ``User `` object and inject it into our action. This can be done
56
57
by implementing the :class: `Symfony\\ Component\\ HttpKernel\\ Controller\\ ArgumentValueResolverInterface `.
57
- This interface specifies that we have to implement two methods::
58
+ This interface specifies that you have to implement two methods::
58
59
59
60
interface ArgumentValueResolverInterface
60
61
{
61
62
public function supports(Request $request, ArgumentMetadata $argument);
62
63
public function resolve(Request $request, ArgumentMetadata $argument);
63
64
}
64
65
65
- - The ``supports()`` method is used to check whether the resolver supports the given argument. It will
66
+ * The ``supports()`` method is used to check whether the resolver supports the given argument. It will
66
67
only continue if it returns ``true``.
67
68
68
- - The ``resolve()`` method will be used to resolve the actual value just acknowledged by
69
+ * The ``resolve()`` method will be used to resolve the actual value just acknowledged by
69
70
``supports()``. Once a value is resolved you can ``yield`` the value to the ``ArgumentResolver``.
70
71
71
- - The ``Request`` object is the current ``Request`` which would also be injected into your
72
+ * The ``Request`` object is the current ``Request`` which would also be injected into your
72
73
action in the forementioned functionality.
73
74
74
- - The :class:``Symfony\\Component\\HttpKernel\\ControllerMetadata\\ArgumentMetadata`` represents
75
+ * The :class:``Symfony\\Component\\HttpKernel\\ControllerMetadata\\ArgumentMetadata`` represents
75
76
information retrieved from the method signature for the current argument it's trying to resolve.
76
77
77
78
.. note ::
79
+
78
80
The ``ArgumentMetadata `` is a simple data container created by the
79
81
:class: ``Symfony\\ Component\\ HttpKernel\\ ControllerMetadata\\ ArgumentMetadataFactory` `. This
80
- factory will work on every supported php version but might give different results. E.g. the
81
- ``isVariadic() `` will never return true on php 5.5 and only on php 7.0 and higher it will give
82
+ factory will work on every supported PHP version but might give different results. E.g. the
83
+ ``isVariadic() `` will never return true on PHP 5.5 and only on PHP 7.0 and higher it will give
82
84
you basic types when calling ``getType() ``.
83
85
84
- Now that we know what to do, we can implement this interface. In order to get the current ``User ``,
85
- we will have to get it from the ``TokenInterface `` which is in the ``TokenStorageInterface ``::
86
+ Now that you know what to do, you can implement this interface. In order to get the current ``User ``,
87
+ you will have to get it from the ``TokenInterface `` which is in the ``TokenStorageInterface ``::
86
88
87
89
namespace AppBundle\ArgumentValueResolver;
88
90
@@ -110,10 +112,11 @@ we will have to get it from the ``TokenInterface`` which is in the ``TokenStorag
110
112
}
111
113
}
112
114
113
- This was pretty simple, now all we have to do is add the configuration for the service container. This
115
+ This was pretty simple, now all you have to do is add the configuration for the service container. This
114
116
can be done by tagging the service with ``kernel.argument_resolver `` and adding a priority.
115
117
116
118
.. note ::
119
+
117
120
While adding a priority is optional, it's recommended to add one to make sure the expected
118
121
value is injected. The ``ArgumentFromAttributeResolver `` has a priority of 100. As this
119
122
one is responsible for fetching attributes from the ``Request ``, it's also recommended to
0 commit comments