@@ -1340,6 +1340,23 @@ have been renamed. Let's say you have a route called ``product_show``:
1340
1340
1341
1341
.. configuration-block ::
1342
1342
1343
+ .. code-block :: php-attributes
1344
+
1345
+ // src/Controller/ProductController.php
1346
+ namespace App\Controller;
1347
+
1348
+ use Symfony\Component\HttpFoundation\Response;
1349
+ use Symfony\Component\Routing\Attribute\Route;
1350
+
1351
+ class ProductController
1352
+ {
1353
+ #[Route('/product/{id}', name: 'product_show')]
1354
+ public function show(): Response
1355
+ {
1356
+ // ...
1357
+ }
1358
+ }
1359
+
1343
1360
.. code-block :: yaml
1344
1361
1345
1362
# config/routes.yaml
@@ -1376,6 +1393,25 @@ Instead of duplicating the original route, you can create an alias for it.
1376
1393
1377
1394
.. configuration-block ::
1378
1395
1396
+ .. code-block :: php-attributes
1397
+
1398
+ // src/Controller/ProductController.php
1399
+ namespace App\Controller;
1400
+
1401
+ use Symfony\Component\HttpFoundation\Response;
1402
+ use Symfony\Component\Routing\Attribute\Route;
1403
+
1404
+ class ProductController
1405
+ {
1406
+ // "alias" named argument refers to the name of the alias you want to create.
1407
+ // The alias will point to the actual route "product_show"
1408
+ #[Route('/product/{id}', name: 'product_show', alias: ['product_details'])]
1409
+ public function show(): Response
1410
+ {
1411
+ // ...
1412
+ }
1413
+ }
1414
+
1379
1415
.. code-block :: yaml
1380
1416
1381
1417
# config/routes.yaml
@@ -1436,6 +1472,42 @@ This way, the ``product_show`` alias could be deprecated.
1436
1472
1437
1473
.. configuration-block ::
1438
1474
1475
+ .. code-block :: php-attributes
1476
+
1477
+ // src/Controller/ProductController.php
1478
+ namespace App\Controller;
1479
+
1480
+ use Symfony\Component\HttpFoundation\Response;
1481
+ use Symfony\Component\Routing\Attribute\Route;
1482
+
1483
+ class ProductController
1484
+ {
1485
+ // this outputs the following generic deprecation message:
1486
+ // Since acme/package 1.2: The "product_show" route alias is deprecated. You should stop using it, as it will be removed in the future.
1487
+ #[Route('/product/{id}',
1488
+ name: 'product_details',
1489
+ alias: new DeprecatedAlias(
1490
+ aliasName: 'product_show',
1491
+ package: 'acme/package',
1492
+ version: '1.2',
1493
+ ),
1494
+ )]
1495
+ // Or, you can also define a custom deprecation message (%alias_id% placeholder is available)
1496
+ #[Route('/product/{id}',
1497
+ name: 'product_details',
1498
+ alias: new DeprecatedAlias(
1499
+ aliasName: 'product_show',
1500
+ package: 'acme/package',
1501
+ version: '1.2',
1502
+ message: 'The "%alias_id%" route alias is deprecated. Please use "product_details" instead.',
1503
+ ),
1504
+ )]
1505
+ public function show(): Response
1506
+ {
1507
+ // ...
1508
+ }
1509
+ }
1510
+
1439
1511
.. code-block :: yaml
1440
1512
1441
1513
# Move the concrete route definition under ``product_details``
0 commit comments