Skip to content

Commit 0127836

Browse files
author
Mathieu
committed
Starting over
1 parent 5a2af0f commit 0127836

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

controller/value_resolver.rst

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,27 @@ PSR-7 Objects Resolver:
204204
:class:`Psr\\Http\\Message\\RequestInterface` or :class:`Psr\\Http\\Message\\MessageInterface`.
205205
It requires installing :doc:`the PSR-7 Bridge </components/psr7>` component.
206206

207+
Managing Value Resolvers
208+
------------------------
209+
210+
For each argument, every available resolver will be called until one provides a value.
211+
The order in which they are called depends on their priority.
212+
For example, the ``SessionValueResolver`` (priority 50) will be called before the
213+
``DefaultValueResolver`` (priority -100) which allows to write e.g.
214+
``SessionInterface $session = null`` to get the session if there is one, or ``null``
215+
if there is none.
216+
217+
But what if you *know* there will be a session? In that case every resolver running
218+
before ``SessionValueResolver`` is useless. Worse, some other resolver could actually
219+
provide a value before ``SessionValueResolver`` has a chance to (don't worry though,
220+
this won't happen with built-in resolvers). Since Symfony 6.3, you can leverage the
221+
:class:`Symfony\\Component\\HttpKernel\\Attribute\\ValueResolver` to avoid this kind of
222+
issue.
223+
224+
.. versionadded:: 6.3
225+
226+
The ``ValueResolver`` attribute was introduced in Symfony 6.3.
227+
207228
Adding a Custom Value Resolver
208229
------------------------------
209230

0 commit comments

Comments
 (0)