@@ -355,3 +355,47 @@ command to see which argument resolvers are present and in which order they run:
355
355
.. code-block :: terminal
356
356
357
357
$ php bin/console debug:container debug.argument_resolver.inner --show-arguments
358
+
359
+ Using a Specific Value Resolver
360
+ -------------------------------
361
+
362
+ .. versionadded :: 6.3
363
+
364
+ The ``ValueResolver `` attribute was introduced in Symfony 6.3.
365
+
366
+ The priority-based system is designed to support the vast majority of use-cases,
367
+ but it has limits: every resolver will be called until one provide some value.
368
+ Not only is this inefficient if you already know how your parameter must be resolved,
369
+ you could not even be sure which resolver did provide a value.
370
+
371
+ You can tackle these two issues at once by adding a ``ValueResolver `` attribute
372
+ to such parameters:
373
+
374
+ // src/Controller/DefaultController.php
375
+ namespace App\C ontroller;
376
+
377
+ use Symfony\C omponent\H ttpFoundation\R esponse;
378
+ use Symfony\C omponent\H ttpKernel\A ttribute\V alueResolver;
379
+ use Symfony\C omponent\H ttpKernel\C ontroller\A rgumentResolver\D efaultValueResolver;
380
+ use Symfony\C omponent\R outing\A nnotation\R oute;
381
+
382
+ class DefaultController
383
+ {
384
+ #[Route('/{page}')]
385
+ public function list(
386
+ #[ValueResolver(DefaultValueResolver::class)]
387
+ int $page = 1,
388
+ ): Response {
389
+ /*
390
+ * Here $page would always be 1: the RequestAttributeValueResolver would not kick in
391
+ * because we asked the DefaultValueResolver only to provide a value.
392
+ */
393
+ }
394
+ }
395
+
396
+ Its only argument is the resolver's name. That is,
397
+ its definition's ``controller.argument_value_resolver `` tag ``name `` attribute.
398
+ For built-in resolvers, this is the same as their FQCN.
399
+
400
+ Note that the specified resolver **must ** provide a value.
401
+ Else, an exception will be thrown.
0 commit comments