Skip to content

Commit 358e141

Browse files
committed
Merge branch '4.4' into 5.2
* 4.4: [Session] Update configurations
2 parents 0c73d58 + b217159 commit 358e141

File tree

3 files changed

+80
-9
lines changed

3 files changed

+80
-9
lines changed

components/http_foundation/session_configuration.rst

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ All native save handlers are internal to PHP and as such, have no public facing
2929
They must be configured by ``php.ini`` directives, usually ``session.save_path`` and
3030
potentially other driver specific directives. Specific details can be found in
3131
the docblock of the ``setOptions()`` method of each class. For instance, the one
32-
provided by the Memcached extension can be found on :phpmethod:`php.net <Memcached::setOption>`.
32+
provided by the Memcached extension can be found on :phpmethod:`php.net <Memcached::setOptions>`.
3333

3434
While native save handlers can be activated by directly using
3535
``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``.
170170
If you wish to use the original value set in your ``php.ini``, add the following
171171
configuration:
172172

173-
.. code-block:: yaml
173+
.. configuration-block::
174174

175-
# config/packages/framework.yaml
176-
framework:
177-
session:
178-
gc_probability: null
175+
.. code-block:: yaml
176+
177+
# config/packages/framework.yaml
178+
framework:
179+
session:
180+
gc_probability: null
181+
182+
.. code-block:: xml
183+
184+
<!-- config/packages/framework.xml -->
185+
<?xml version="1.0" encoding="UTF-8" ?>
186+
<container xmlns="http://symfony.com/schema/dic/services"
187+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
188+
xmlns:framework="http://symfony.com/schema/dic/symfony"
189+
xsi:schemaLocation="http://symfony.com/schema/dic/services
190+
https://symfony.com/schema/dic/services/services-1.0.xsd
191+
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
192+
193+
<framework:config>
194+
<framework:session gc_probability="null"/>
195+
</framework:config>
196+
</container>
197+
198+
.. code-block:: php
199+
200+
// config/packages/framework.php
201+
$container->loadFromExtension('framework', [
202+
'session' => [
203+
'gc_probability' => null,
204+
],
205+
]);
179206
180207
You can configure these settings by passing ``gc_probability``, ``gc_divisor``
181208
and ``gc_maxlifetime`` in an array to the constructor of

session.rst

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,50 @@ the default ``AttributeBag`` by the ``NamespacedAttributeBag``:
186186
session.namespacedattributebag:
187187
class: Symfony\Component\HttpFoundation\Session\Attribute\NamespacedAttributeBag
188188
189+
.. code-block:: xml
190+
191+
<!-- config/services.xml -->
192+
<?xml version="1.0" encoding="UTF-8" ?>
193+
<container xmlns="http://symfony.com/schema/dic/services"
194+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
195+
xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd">
196+
197+
<services>
198+
<service id="session" class="Symfony\Component\HttpFoundation\Session\Session" public="true">
199+
<argument type="service" id="session.storage"/>
200+
<argument type="service" id="session.namespacedattributebag"/>
201+
<argument type="service" id="session.flash_bag"/>
202+
</service>
203+
204+
<service id="session.namespacedattributebag"
205+
class="Symfony\Component\HttpFoundation\Session\Attribute\NamespacedAttributeBag"
206+
/>
207+
</services>
208+
</container>
209+
210+
.. code-block:: php
211+
212+
// config/services.php
213+
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
214+
215+
use Symfony\Component\HttpFoundation\Session\Attribute\NamespacedAttributeBag;
216+
use Symfony\Component\HttpFoundation\Session\Session;
217+
218+
return function(ContainerConfigurator $configurator) {
219+
$services = $configurator->services();
220+
221+
$services->set('session', Session::class)
222+
->public()
223+
->args([
224+
ref('session.storage'),
225+
ref('session.namespacedattributebag'),
226+
ref('session.flash_bag'),
227+
])
228+
;
229+
230+
$services->set('session.namespacedattributebag', NamespacedAttributeBag::class);
231+
};
232+
189233
.. _session-avoid-start:
190234

191235
Avoid Starting Sessions for Anonymous Users

session/database.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,6 @@ First, define a Symfony service for the connection to the Redis server:
6363
6464
.. code-block:: php
6565
66-
use Symfony\Component\DependencyInjection\Reference;
67-
6866
// ...
6967
$container
7068
// you can also use \RedisArray, \RedisCluster or \Predis\Client classes
@@ -105,13 +103,15 @@ and ``RedisProxy``:
105103
and the expiration time for any given entry (in seconds), defaults are 'sf_s' and null:
106104
<argument type="collection">
107105
<argument key="prefix">my_prefix</argument>
106+
<argument key="ttl">600</argument>
108107
</argument> -->
109108
</service>
110109
</services>
111110
112111
.. code-block:: php
113112
114113
// config/services.php
114+
use Symfony\Component\DependencyInjection\Reference;
115115
use Symfony\Component\HttpFoundation\Session\Storage\Handler\RedisSessionHandler;
116116
117117
$container
@@ -208,7 +208,7 @@ first register a new handler service with your database credentials:
208208
<argument>%env(DATABASE_URL)%</argument>
209209
210210
<!-- you can also use PDO configuration, but requires passing two arguments: -->
211-
<!-- <argument>mysql:dbname=mydatabase, host=myhost</argument>
211+
<!-- <argument>mysql:dbname=mydatabase; host=myhost; port=myport</argument>
212212
<argument type="collection">
213213
<argument key="db_username">myuser</argument>
214214
<argument key="db_password">mypassword</argument>

0 commit comments

Comments
 (0)