diff --git a/components/http_foundation/session_configuration.rst b/components/http_foundation/session_configuration.rst index c8b29fb00b4..fdaa7ba7eda 100644 --- a/components/http_foundation/session_configuration.rst +++ b/components/http_foundation/session_configuration.rst @@ -29,7 +29,7 @@ All native save handlers are internal to PHP and as such, have no public facing They must be configured by ``php.ini`` directives, usually ``session.save_path`` and potentially other driver specific directives. Specific details can be found in the docblock of the ``setOptions()`` method of each class. For instance, the one -provided by the Memcached extension can be found on :phpmethod:`php.net `. +provided by the Memcached extension can be found on :phpmethod:`php.net `. While native save handlers can be activated by directly using ``ini_set('session.save_handler', $name);``, Symfony provides a convenient way to @@ -170,12 +170,39 @@ collection. That's why Symfony now overwrites this value to ``1``. If you wish to use the original value set in your ``php.ini``, add the following configuration: -.. code-block:: yaml +.. configuration-block:: - # config/packages/framework.yaml - framework: - session: - gc_probability: null + .. code-block:: yaml + + # config/packages/framework.yaml + framework: + session: + gc_probability: null + + .. code-block:: xml + + + + + + + + + + + .. code-block:: php + + // config/packages/framework.php + $container->loadFromExtension('framework', [ + 'session' => [ + 'gc_probability' => null, + ], + ]); You can configure these settings by passing ``gc_probability``, ``gc_divisor`` and ``gc_maxlifetime`` in an array to the constructor of diff --git a/session.rst b/session.rst index fb9bb81cd8a..6465cdb3b54 100644 --- a/session.rst +++ b/session.rst @@ -186,6 +186,50 @@ the default ``AttributeBag`` by the ``NamespacedAttributeBag``: session.namespacedattributebag: class: Symfony\Component\HttpFoundation\Session\Attribute\NamespacedAttributeBag + .. code-block:: xml + + + + + + + + + + + + + + + + + .. code-block:: php + + // config/services.php + namespace Symfony\Component\DependencyInjection\Loader\Configurator; + + use Symfony\Component\HttpFoundation\Session\Attribute\NamespacedAttributeBag; + use Symfony\Component\HttpFoundation\Session\Session; + + return function(ContainerConfigurator $configurator) { + $services = $configurator->services(); + + $services->set('session', Session::class) + ->public() + ->args([ + ref('session.storage'), + ref('session.namespacedattributebag'), + ref('session.flash_bag'), + ]) + ; + + $services->set('session.namespacedattributebag', NamespacedAttributeBag::class); + }; + .. _session-avoid-start: Avoid Starting Sessions for Anonymous Users diff --git a/session/database.rst b/session/database.rst index 6a69c172c16..8bf72d00768 100644 --- a/session/database.rst +++ b/session/database.rst @@ -63,8 +63,6 @@ First, define a Symfony service for the connection to the Redis server: .. code-block:: php - use Symfony\Component\DependencyInjection\Reference; - // ... $container // you can also use \RedisArray, \RedisCluster or \Predis\Client classes @@ -90,7 +88,7 @@ and ``RedisProxy``: arguments: - '@Redis' # you can optionally pass an array of options. The only options are 'prefix' and 'ttl', - # which define the prefix to use for the keys to avoid collision on the Redis server + # which define the prefix to use for the keys to avoid collision on the Redis server # and the expiration time for any given entry (in seconds), defaults are 'sf_s' and null: # - { 'prefix': 'my_prefix', 'ttl': 600 } @@ -101,10 +99,11 @@ and ``RedisProxy``: @@ -112,6 +111,7 @@ and ``RedisProxy``: .. code-block:: php // config/services.php + use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\HttpFoundation\Session\Storage\Handler\RedisSessionHandler; $container @@ -119,7 +119,7 @@ and ``RedisProxy``: ->addArgument( new Reference('Redis'), // you can optionally pass an array of options. The only options are 'prefix' and 'ttl', - // which define the prefix to use for the keys to avoid collision on the Redis server + // which define the prefix to use for the keys to avoid collision on the Redis server // and the expiration time for any given entry (in seconds), defaults are 'sf_s' and null: // ['prefix' => 'my_prefix', 'ttl' => 600], ); @@ -208,7 +208,7 @@ first register a new handler service with your database credentials: %env(DATABASE_URL)% -