In the controller guide, you've learned that you can get the
Request object via an argument in
your controller. This argument has to be type-hinted by the Request class
in order to be recognized. This is done via the
ArgumentResolver. By
creating and registering custom argument value resolvers, you can extend this
functionality.

Injects the object that represents the current logged in user if type-hinted
with UserInterface. Default value can be set to null in case
the controller can be accessed by anonymous users. It requires installing
the Security component.

Psr7ServerRequestResolver

Injects a PSR-7 compliant version of the current request if type-hinted
with RequestInterface, MessageInterface or ServerRequestInterface.
It requires installing the SensioFrameworkExtraBundle.

Beware that this feature is already provided by the @ParamConverter
annotation from the SensioFrameworkExtraBundle. If you have that bundle
installed in your project, add this config to disable the auto-conversion of
type-hinted method arguments:

While adding a priority is optional, it's recommended to add one to make sure
the expected value is injected. The RequestAttributeValueResolver has a
priority of 100. As this one is responsible for fetching attributes from the
Request, it's recommended to trigger your custom value resolver with a
lower priority. This makes sure the argument resolvers are not triggered when
the attribute is present. For instance, when passing the user along a
sub-requests.

Tip

As you can see in the UserValueResolver::supports() method, the user
may not be available (e.g. when the controller is not behind a firewall).
In these cases, the resolver will not be executed. If no argument value
is resolved, an exception will be thrown.

To prevent this, you can add a default value in the controller (e.g. User
$user = null). The DefaultValueResolver is executed as the last
resolver and will use the default value if no value was already resolved.