Skip to content

Commit ce2a6cd

Browse files
committed
minor #16074 [Routing] Document the new alias feature (Lctrs)
This PR was merged into the 5.4 branch. Discussion ---------- [Routing] Document the new alias feature Closes #16070. Commits ------- 194ca17 [Routing] Document the new alias feature
2 parents 52a06e0 + 194ca17 commit ce2a6cd

File tree

1 file changed

+111
-0
lines changed

1 file changed

+111
-0
lines changed

routing.rst

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

1471+
.. _routing-alias:
1472+
1473+
Aliasing
1474+
--------
1475+
1476+
.. versionadded:: 5.4
1477+
1478+
Support for route aliases was introduced in Symfony 5.4.
1479+
1480+
You may sometimes want to have multiple names for the same route. You can do so by
1481+
aliasing them.
1482+
1483+
.. configuration-block::
1484+
1485+
.. code-block:: yaml
1486+
1487+
# config/routes.yaml
1488+
alias_name:
1489+
alias: target_route_name
1490+
1491+
.. code-block:: xml
1492+
1493+
<!-- config/routes.xml -->
1494+
<?xml version="1.0" encoding="UTF-8" ?>
1495+
<routes xmlns="http://symfony.com/schema/routing"
1496+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
1497+
xsi:schemaLocation="http://symfony.com/schema/routing
1498+
https://symfony.com/schema/routing/routing-1.0.xsd">
1499+
1500+
<route id="alias_name" alias="target_route_name"/>
1501+
</routes>
1502+
1503+
.. code-block:: php
1504+
1505+
// config/routes.php
1506+
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
1507+
1508+
return function (RoutingConfigurator $routes) {
1509+
$routes->alias('alias_name', 'target_route_name');
1510+
};
1511+
1512+
.. _routing-alias-deprecation:
1513+
1514+
Deprecating Route Aliases
1515+
~~~~~~~~~~~~~~~~~~~~~~~~~
1516+
1517+
If you decide to deprecate the use of a route alias (because it is outdated or
1518+
you decided not to maintain it anymore), you can deprecate its definition:
1519+
1520+
.. configuration-block::
1521+
1522+
.. code-block:: yaml
1523+
1524+
alias_name:
1525+
alias: target_route_name
1526+
1527+
# this outputs the following generic deprecation message:
1528+
# Since acme/package 1.2: The "alias_name" route alias is deprecated. You should stop using it, as it will be removed in the future.
1529+
deprecated:
1530+
package: 'acme/package'
1531+
version: '1.2'
1532+
1533+
# you can also define a custom deprecation message (%alias_id% placeholder is available)
1534+
deprecated:
1535+
package: 'acme/package'
1536+
version: '1.2'
1537+
message: 'The "%alias_id%" route alias is deprecated. Do not use it anymore.'
1538+
1539+
.. code-block:: xml
1540+
1541+
<?xml version="1.0" encoding="UTF-8" ?>
1542+
<routes xmlns="http://symfony.com/schema/routing"
1543+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
1544+
xsi:schemaLocation="http://symfony.com/schema/routing
1545+
https://symfony.com/schema/routing/routing-1.0.xsd">
1546+
1547+
<route id="alias_name" alias="target_route_name">
1548+
<!-- this outputs the following generic deprecation message:
1549+
Since acme/package 1.2: The "alias_name" route alias is deprecated. You should stop using it, as it will be removed in the future. -->
1550+
<deprecated package="acme/package" version="1.2"/>
1551+
1552+
<!-- you can also define a custom deprecation message (%alias_id% placeholder is available) -->
1553+
<deprecated package="acme/package" version="1.2">
1554+
The "%alias_id%" route alias is deprecated. Do not use it anymore.
1555+
</deprecated>
1556+
</route>
1557+
</routes>
1558+
1559+
.. code-block:: php
1560+
1561+
$routes->alias('alias_name', 'target_route_name')
1562+
1563+
// this outputs the following generic deprecation message:
1564+
// Since acme/package 1.2: The "alias_name" route alias is deprecated. You should stop using it, as it will be removed in the future.
1565+
->deprecate('acme/package', '1.2', '')
1566+
1567+
// you can also define a custom deprecation message (%alias_id% placeholder is available)
1568+
->deprecate(
1569+
'acme/package',
1570+
'1.2',
1571+
'The "%alias_id%" route alias is deprecated. Do not use it anymore.'
1572+
)
1573+
;
1574+
1575+
Now, every time this route alias is used, a deprecation warning is triggered,
1576+
advising you to stop or to change your uses of that alias.
1577+
1578+
The message is actually a message template, which replaces occurrences of the
1579+
``%alias_id%`` placeholder by the route alias name. You **must** have
1580+
at least one occurrence of the ``%alias_id%`` placeholder in your template.
1581+
14711582
.. _routing-route-groups:
14721583

14731584
Route Groups and Prefixes

0 commit comments

Comments
 (0)