Skip to content

Commit 8b30d20

Browse files
committed
Merge branch '7.0' into 7.1
* 7.0: remove versionadded directive for Symfony 6 remove 6.x versionnaded in webhook Remove @dev Remove @dev [Routing][Security] Document the `LogoutRouteLoader`
2 parents 54478c1 + 6de3f76 commit 8b30d20

File tree

3 files changed

+124
-49
lines changed

3 files changed

+124
-49
lines changed

security.rst

Lines changed: 120 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1768,7 +1768,7 @@ To enable logging out, activate the ``logout`` config parameter under your fire
17681768
main:
17691769
# ...
17701770
logout:
1771-
path: app_logout
1771+
path: /logout
17721772
17731773
# where to redirect after logout
17741774
# target: app_any_route
@@ -1789,11 +1789,10 @@ To enable logging out, activate the ``logout`` config parameter under your fire
17891789
<!-- ... -->
17901790
17911791
<firewall name="main">
1792-
<!-- ... -->
1793-
<logout path="app_logout"/>
1792+
<logout path="/logout"/>
17941793
17951794
<!-- use "target" to configure where to redirect after logout
1796-
<logout path="app_logout" target="app_any_route"/>
1795+
<logout path="/logout" target="app_any_route"/>
17971796
-->
17981797
</firewall>
17991798
</config>
@@ -1810,69 +1809,54 @@ To enable logging out, activate the ``logout`` config parameter under your fire
18101809
$mainFirewall = $security->firewall('main');
18111810
// ...
18121811
$mainFirewall->logout()
1813-
// the argument can be either a route name or a path
1814-
->path('app_logout')
1812+
->path('/logout')
18151813
18161814
// where to redirect after logout
18171815
// ->target('app_any_route')
18181816
;
18191817
};
18201818
1821-
Next, you need to create a route for this URL (but not a controller):
1819+
Symfony will then un-authenticate users navigating to the configured ``path``,
1820+
and redirect them to the configured ``target``.
18221821

1823-
.. configuration-block::
1824-
1825-
.. code-block:: php-attributes
1822+
.. tip::
18261823

1827-
// src/Controller/SecurityController.php
1828-
namespace App\Controller;
1824+
If you need to reference the logout path, you can use the ``_logout_<firewallname>``
1825+
route name (e.g. ``_logout_main``).
18291826

1830-
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
1831-
use Symfony\Component\Routing\Annotation\Route;
1827+
If your project does not use :ref:`Symfony Flex <symfony-flex>`, make sure
1828+
you have imported the logout route loader in your routes:
18321829

1833-
class SecurityController extends AbstractController
1834-
{
1835-
#[Route('/logout', name: 'app_logout', methods: ['GET'])]
1836-
public function logout(): never
1837-
{
1838-
// controller can be blank: it will never be called!
1839-
throw new \Exception('Don\'t forget to activate logout in security.yaml');
1840-
}
1841-
}
1830+
.. configuration-block::
18421831

18431832
.. code-block:: yaml
18441833
1845-
# config/routes.yaml
1846-
app_logout:
1847-
path: /logout
1848-
methods: GET
1834+
# config/routes/security.yaml
1835+
_symfony_logout:
1836+
resource: security.route_loader.logout
1837+
type: service
18491838
18501839
.. code-block:: xml
18511840
1852-
<!-- config/routes.xml -->
1841+
<!-- config/routes/security.xml -->
18531842
<?xml version="1.0" encoding="UTF-8" ?>
18541843
<routes xmlns="http://symfony.com/schema/routing"
18551844
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
18561845
xsi:schemaLocation="http://symfony.com/schema/routing
18571846
https://symfony.com/schema/routing/routing-1.0.xsd">
18581847
1859-
<route id="app_logout" path="/logout" methods="GET"/>
1848+
<import resource="security.route_loader.logout" type="service"/>
18601849
</routes>
18611850
18621851
.. code-block:: php
18631852
1864-
// config/routes.php
1853+
// config/routes/security.php
18651854
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
18661855
1867-
return function (RoutingConfigurator $routes): void {
1868-
$routes->add('app_logout', '/logout')
1869-
->methods(['GET'])
1870-
;
1856+
return static function (RoutingConfigurator $routes): void {
1857+
$routes->import('security.route_loader.logout', 'service');
18711858
};
18721859
1873-
That's it! By sending a user to the ``app_logout`` route (i.e. to ``/logout``)
1874-
Symfony will un-authenticate the current user and redirect them.
1875-
18761860
Logout programmatically
18771861
~~~~~~~~~~~~~~~~~~~~~~~
18781862

@@ -1950,6 +1934,105 @@ to execute custom logic::
19501934
}
19511935
}
19521936

1937+
Customizing Logout Path
1938+
~~~~~~~~~~~~~~~~~~~~~~~
1939+
1940+
Another option is to configure ``path`` as a route name. This can be useful
1941+
if you want logout URIs to be dynamic (e.g. translated according to the
1942+
current locale). In that case, you have to create this route yourself:
1943+
1944+
.. configuration-block::
1945+
1946+
.. code-block:: yaml
1947+
1948+
# config/routes.yaml
1949+
app_logout:
1950+
path:
1951+
en: /logout
1952+
fr: /deconnexion
1953+
methods: GET
1954+
1955+
.. code-block:: xml
1956+
1957+
<!-- config/routes.xml -->
1958+
<?xml version="1.0" encoding="UTF-8" ?>
1959+
<routes xmlns="http://symfony.com/schema/routing"
1960+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
1961+
xsi:schemaLocation="http://symfony.com/schema/routing
1962+
https://symfony.com/schema/routing/routing-1.0.xsd">
1963+
1964+
<route id="app_logout" path="/logout" methods="GET">
1965+
<path locale="en">/logout</path>
1966+
<path locale="fr">/deconnexion</path>
1967+
</route>
1968+
</routes>
1969+
1970+
.. code-block:: php
1971+
1972+
// config/routes.php
1973+
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
1974+
1975+
return function (RoutingConfigurator $routes): void {
1976+
$routes->add('app_logout', [
1977+
'en' => '/logout',
1978+
'fr' => '/deconnexion',
1979+
])
1980+
->methods(['GET'])
1981+
;
1982+
};
1983+
1984+
Then, pass the route name to the ``path`` option:
1985+
1986+
.. configuration-block::
1987+
1988+
.. code-block:: yaml
1989+
1990+
# config/packages/security.yaml
1991+
security:
1992+
# ...
1993+
1994+
firewalls:
1995+
main:
1996+
# ...
1997+
logout:
1998+
path: app_logout
1999+
2000+
.. code-block:: xml
2001+
2002+
<!-- config/packages/security.xml -->
2003+
<?xml version="1.0" encoding="UTF-8" ?>
2004+
<srv:container xmlns="http://symfony.com/schema/dic/security"
2005+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2006+
xmlns:srv="http://symfony.com/schema/dic/services"
2007+
xsi:schemaLocation="http://symfony.com/schema/dic/services
2008+
https://symfony.com/schema/dic/services/services-1.0.xsd
2009+
http://symfony.com/schema/dic/security
2010+
https://symfony.com/schema/dic/security/security-1.0.xsd">
2011+
2012+
<config>
2013+
<!-- ... -->
2014+
2015+
<firewall name="main">
2016+
<logout path="app_logout"/>
2017+
</firewall>
2018+
</config>
2019+
</srv:container>
2020+
2021+
.. code-block:: php
2022+
2023+
// config/packages/security.php
2024+
use Symfony\Config\SecurityConfig;
2025+
2026+
return static function (SecurityConfig $security): void {
2027+
// ...
2028+
2029+
$mainFirewall = $security->firewall('main');
2030+
// ...
2031+
$mainFirewall->logout()
2032+
->path('app_logout')
2033+
;
2034+
};
2035+
19532036
.. _retrieving-the-user-object:
19542037

19552038
Fetching the User Object

setup.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ application:
4646
.. code-block:: terminal
4747
4848
# run this if you are building a traditional web application
49-
$ symfony new my_project_directory --version="7.0.*@dev" --webapp
49+
$ symfony new my_project_directory --version="7.0.*" --webapp
5050
5151
# run this if you are building a microservice, console application or API
52-
$ symfony new my_project_directory --version="7.0.*@dev"
52+
$ symfony new my_project_directory --version="7.0.*"
5353
5454
The only difference between these two commands is the number of packages
5555
installed by default. The ``--webapp`` option installs all the packages that you
@@ -61,12 +61,12 @@ Symfony application using Composer:
6161
.. code-block:: terminal
6262
6363
# run this if you are building a traditional web application
64-
$ composer create-project symfony/skeleton:"7.0.*@dev" my_project_directory
64+
$ composer create-project symfony/skeleton:"7.0.*" my_project_directory
6565
$ cd my_project_directory
6666
$ composer require webapp
6767
6868
# run this if you are building a microservice, console application or API
69-
$ composer create-project symfony/skeleton:"7.0.*@dev" my_project_directory
69+
$ composer create-project symfony/skeleton:"7.0.*" my_project_directory
7070
7171
No matter which command you run to create the Symfony application. All of them
7272
will create a new ``my_project_directory/`` directory, download some dependencies

webhook.rst

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -145,14 +145,6 @@ Twilio ``notifier.webhook.request_parser.twilio``
145145
Vonage ``notifier.webhook.request_parser.vonage``
146146
============ ==========================================
147147

148-
.. versionadded:: 6.3
149-
150-
The support for Twilio was introduced in Symfony 6.3.
151-
152-
.. versionadded:: 6.4
153-
154-
The support for Vonage was introduced in Symfony 6.4.
155-
156148
For SMS transports, an additional ``SmsEvent`` is available in the RemoteEvent
157149
consumer::
158150

0 commit comments

Comments
 (0)