@@ -985,6 +985,35 @@ Check out the :ref:`Doctrine param conversion documentation <doctrine-entity-val
985
985
to learn about the ``#[MapEntity] `` attribute that can be used to customize the
986
986
database queries used to fetch the object from the route parameter.
987
987
988
+ Backed Enum Parameters
989
+ ~~~~~~~~~~~~~~~~~~~~~~
990
+
991
+ .. versionadded :: 6.3
992
+
993
+ The support of ``\BackedEnum `` as route parameters was introduced Symfony 6.3.
994
+
995
+ You can use PHP `backed enumerations `_ as route parameters because Symfony will
996
+ convert them automatically to their scalar values.
997
+
998
+ .. code-block :: php-attributes
999
+
1000
+ // src/Controller/DefaultController.php
1001
+ namespace App\Controller;
1002
+
1003
+ use App\Enum\OrderStatusEnum;
1004
+ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
1005
+ use Symfony\Component\HttpFoundation\Response;
1006
+ use Symfony\Component\Routing\Annotation\Route;
1007
+
1008
+ class OrderController extends AbstractController
1009
+ {
1010
+ #[Route('/orders/list/{status}', name: 'list_orders_by_status')]
1011
+ public function list(OrderStatusEnum $status = OrderStatusEnum::Paid): Response
1012
+ {
1013
+ // ...
1014
+ }
1015
+ }
1016
+
988
1017
Special Parameters
989
1018
~~~~~~~~~~~~~~~~~~
990
1019
@@ -1245,35 +1274,6 @@ A possible solution is to change the parameter requirements to be more permissiv
1245
1274
as the token and the format will be empty. This can be solved by replacing
1246
1275
the ``.+ `` requirement by ``[^.]+ `` to allow any character except dots.
1247
1276
1248
- Backed Enum as Parameter
1249
- ~~~~~~~~~~~~~~~~~~~~~~~~
1250
-
1251
- PHP 8.1 add support for Backed Enum, they can be used as route parameter and
1252
- automatically converted to their value by Symfony.
1253
-
1254
- .. versionadded :: 6.3
1255
-
1256
- Using a `\BackedEnum ` as route parameter is available since Symfony 6.3.
1257
-
1258
- .. code-block :: php-attributes
1259
-
1260
- // src/Controller/DefaultController.php
1261
- namespace App\Controller;
1262
-
1263
- use App\Enum\SuitsEnum;
1264
- use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
1265
- use Symfony\Component\HttpFoundation\Response;
1266
- use Symfony\Component\Routing\Annotation\Route;
1267
-
1268
- class DefaultController extends AbstractController
1269
- {
1270
- #[Route('/cards/{suit}', name: 'cards_suit')]
1271
- public function list(SuitsEnum $suit = SuitsEnum::Diamonds): Response
1272
- {
1273
- // ...
1274
- }
1275
- }
1276
-
1277
1277
.. _routing-alias :
1278
1278
1279
1279
Route Aliasing
@@ -2700,3 +2700,4 @@ Learn more about Routing
2700
2700
.. _`PHP regular expressions` : https://www.php.net/manual/en/book.pcre.php
2701
2701
.. _`PCRE Unicode properties` : https://www.php.net/manual/en/regexp.reference.unicode.php
2702
2702
.. _`FOSJsRoutingBundle` : https://github.com/FriendsOfSymfony/FOSJsRoutingBundle
2703
+ .. _`backed enumerations` : https://www.php.net/manual/en/language.enumerations.backed.php
0 commit comments