Skip to content

Commit 05147ec

Browse files
committed
Merge branch '5.0'
* 5.0: [HttpFoundation] Allow to configure session handlers with DSN
2 parents e80941c + 58c09e9 commit 05147ec

File tree

2 files changed

+55
-3
lines changed

2 files changed

+55
-3
lines changed

reference/configuration/framework.rst

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,6 +1212,58 @@ the native PHP session mechanism. Set it to ``'session.handler.native_file'`` to
12121212
let Symfony manage the sessions itself using files to store the session
12131213
metadata.
12141214

1215+
You can also configure the session handler with a DSN. For example:
1216+
1217+
.. configuration-block::
1218+
1219+
.. code-block:: yaml
1220+
1221+
# config/packages/framework.yaml
1222+
framework:
1223+
session:
1224+
# ...
1225+
handler_id: 'redis://localhost'
1226+
handler_id: '%env(REDIS_URL)%'
1227+
handler_id: '%env(DATABASE_URL)%'
1228+
handler_id: 'file://%kernel.project_dir%/var/sessions'
1229+
1230+
.. code-block:: xml
1231+
1232+
<!-- config/packages/framework.xml -->
1233+
<?xml version="1.0" encoding="UTF-8" ?>
1234+
<container xmlns="http://symfony.com/schema/dic/services"
1235+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
1236+
xmlns:framework="http://symfony.com/schema/dic/symfony"
1237+
xsi:schemaLocation="http://symfony.com/schema/dic/services
1238+
https://symfony.com/schema/dic/services/services-1.0.xsd
1239+
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
1240+
1241+
<framework:config>
1242+
<framework:session enabled="true"
1243+
handler-id="redis://localhost"
1244+
handler-id="%env(REDIS_URL)%"
1245+
handler-id="%env(DATABASE_URL)%"
1246+
handler-id="file://%kernel.project_dir%/var/sessions"/>
1247+
</framework:config>
1248+
</container>
1249+
1250+
.. code-block:: php
1251+
1252+
// config/packages/framework.php
1253+
$container->loadFromExtension('framework', [
1254+
'session' => [
1255+
// ...
1256+
'handler_id' => 'redis://localhost',
1257+
'handler_id' => '%env(REDIS_URL)%',
1258+
'handler_id' => '%env(DATABASE_URL)%',
1259+
'handler_id' => 'file://%kernel.project_dir%/var/sessions',
1260+
],
1261+
]);
1262+
1263+
.. versionadded:: 4.4
1264+
1265+
The option to configure the session handler with a DSN was introduced in Symfony 4.4.
1266+
12151267
If you prefer to make Symfony store sessions in a database read
12161268
:doc:`/doctrine/pdo_session_storage`.
12171269

session.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ sessions, check their default configuration:
2121
# enables the support of sessions in the app
2222
enabled: true
2323
# ID of the service used for session storage.
24-
# NULL = means that PHP's default session mechanism is used
24+
# NULL means that Symfony uses PHP default session mechanism
2525
handler_id: null
2626
# improves the security of the cookies used for sessions
2727
cookie_secure: 'auto'
@@ -42,7 +42,7 @@ sessions, check their default configuration:
4242
<!--
4343
enabled: enables the support of sessions in the app
4444
handler-id: ID of the service used for session storage
45-
NULL means that PHP's default session mechanism is used
45+
NULL means that Symfony uses PHP default session mechanism
4646
cookie-secure and cookie-samesite: improves the security of the cookies used for sessions
4747
-->
4848
<framework:session enabled="true"
@@ -60,7 +60,7 @@ sessions, check their default configuration:
6060
// enables the support of sessions in the app
6161
'enabled' => true,
6262
// ID of the service used for session storage
63-
// NULL means that PHP's default session mechanism is used
63+
// NULL means that Symfony uses PHP default session mechanism
6464
'handler_id' => null,
6565
// improves the security of the cookies used for sessions
6666
'cookie_secure' => 'auto',

0 commit comments

Comments
 (0)