Skip to content

Commit 9899476

Browse files
committed
Merge branch '6.4' into 7.0
* 6.4: [FrameworkBundle] Add documentation about using a DSN as the `session.handler_id`
2 parents c3a9d15 + e24e07d commit 9899476

File tree

1 file changed

+72
-2
lines changed

1 file changed

+72
-2
lines changed

reference/configuration/framework.rst

Lines changed: 72 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1610,10 +1610,80 @@ handler_id
16101610

16111611
**type**: ``string`` **default**: ``session.handler.native_file``
16121612

1613-
The service id used for session storage. The default value ``'session.handler.native_file'``
1613+
The service id or DSN used for session storage. The default value ``'session.handler.native_file'``
16141614
will let Symfony manage the sessions itself using files to store the session metadata.
16151615
Set it to ``null`` to use the native PHP session mechanism.
1616-
You can also :ref:`store sessions in a database <session-database>`.
1616+
It is possible to :ref:`store sessions in a database <session-database>`,
1617+
and also to configure the session handler with a DSN:
1618+
1619+
.. configuration-block::
1620+
1621+
.. code-block:: yaml
1622+
1623+
# config/packages/framework.yaml
1624+
framework:
1625+
session:
1626+
# a few possible examples
1627+
handler_id: 'redis://localhost'
1628+
handler_id: '%env(REDIS_URL)%'
1629+
handler_id: '%env(DATABASE_URL)%'
1630+
handler_id: 'file://%kernel.project_dir%/var/sessions'
1631+
1632+
.. code-block:: xml
1633+
1634+
<!-- config/packages/framework.xml -->
1635+
<?xml version="1.0" encoding="UTF-8" ?>
1636+
<container xmlns="http://symfony.com/schema/dic/services"
1637+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
1638+
xmlns:framework="http://symfony.com/schema/dic/symfony"
1639+
xsi:schemaLocation="http://symfony.com/schema/dic/services
1640+
https://symfony.com/schema/dic/services/services-1.0.xsd
1641+
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
1642+
<framework:config>
1643+
<!-- a few possible examples -->
1644+
<framework:session enabled="true"
1645+
handler-id="redis://localhost"
1646+
handler-id="%env(REDIS_URL)%"
1647+
handler-id="%env(DATABASE_URL)%"
1648+
handler-id="file://%kernel.project_dir%/var/sessions"/>
1649+
</framework:config>
1650+
</container>
1651+
1652+
.. code-block:: php
1653+
1654+
// config/packages/framework.php
1655+
use function Symfony\Component\DependencyInjection\Loader\Configurator\env;
1656+
use Symfony\Config\FrameworkConfig;
1657+
1658+
return static function (FrameworkConfig $framework): void {
1659+
// ...
1660+
1661+
$framework->session()
1662+
// a few possible examples
1663+
->handlerId('redis://localhost')
1664+
->handlerId(env('REDIS_URL'))
1665+
->handlerId(env('DATABASE_URL'))
1666+
->handlerId('file://%kernel.project_dir%/var/sessions');
1667+
};
1668+
1669+
.. note::
1670+
1671+
Supported DSN protocols are the following:
1672+
1673+
* ``file``
1674+
* ``redis``
1675+
* ``rediss`` (Redis over TLS)
1676+
* ``memcached`` (requires :doc:`symfony/cache </components/cache>`)
1677+
* ``pdo_oci`` (requires :doc:`doctrine/dbal </doctrine/dbal>`)
1678+
* ``mssql``
1679+
* ``mysql``
1680+
* ``mysql2``
1681+
* ``pgsql``
1682+
* ``postgres``
1683+
* ``postgresql``
1684+
* ``sqlsrv``
1685+
* ``sqlite``
1686+
* ``sqlite3``
16171687

16181688
.. _name:
16191689

0 commit comments

Comments
 (0)