Skip to content

Commit e260ecc

Browse files
committed
minor #18239 [Routing] Backed Enum as route parameter (MrYamous)
This PR was squashed before being merged into the 6.3 branch. Discussion ---------- [Routing] Backed Enum as route parameter Fixes #18214 Commits ------- 0df46f7 [Routing] Backed Enum as route parameter
2 parents 6d5bd8b + 0df46f7 commit e260ecc

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

routing.rst

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,6 +1245,35 @@ A possible solution is to change the parameter requirements to be more permissiv
12451245
as the token and the format will be empty. This can be solved by replacing
12461246
the ``.+`` requirement by ``[^.]+`` to allow any character except dots.
12471247

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+
12481277
.. _routing-alias:
12491278

12501279
Route Aliasing

0 commit comments

Comments
 (0)