Skip to content

Commit a31e2b8

Browse files
committed
Merge branch '5.3' into 5.4
* 5.3: [Session] Update configurations
2 parents 2e47a36 + dd23482 commit a31e2b8

File tree

3 files changed

+74
-39
lines changed

3 files changed

+74
-39
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: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -201,41 +201,49 @@ your ``Session`` object with the default ``AttributeBag`` by the ``NamespacedAtt
201201
session.namespacedattributebag:
202202
class: Symfony\Component\HttpFoundation\Session\Attribute\NamespacedAttributeBag
203203
204-
.. code-block:: php
204+
.. code-block:: xml
205205
206-
namespace App\Session;
206+
<!-- config/services.xml -->
207+
<?xml version="1.0" encoding="UTF-8" ?>
208+
<container xmlns="http://symfony.com/schema/dic/services"
209+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
210+
xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd">
211+
212+
<services>
213+
<service id="session" class="Symfony\Component\HttpFoundation\Session\Session" public="true">
214+
<argument type="service" id="session.storage"/>
215+
<argument type="service" id="session.namespacedattributebag"/>
216+
<argument type="service" id="session.flash_bag"/>
217+
</service>
218+
219+
<service id="session.namespacedattributebag"
220+
class="Symfony\Component\HttpFoundation\Session\Attribute\NamespacedAttributeBag"
221+
/>
222+
</services>
223+
</container>
207224
208-
use Symfony\Component\HttpFoundation\RequestStack;
209-
use Symfony\Component\HttpFoundation\Session\Attribute\NamespacedAttributeBag;
210-
use Symfony\Component\HttpFoundation\Session\Session;
211-
use Symfony\Component\HttpFoundation\Session\SessionInterface;
212-
use Symfony\Component\HttpFoundation\Session\Storage\SessionStorageFactoryInterface;
225+
.. code-block:: php
213226
214-
class SessionFactory
215-
{
216-
private $requestStack;
217-
private $storageFactory;
218-
private $usageReporter;
219-
private $sessionAttributes;
227+
// config/services.php
228+
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
220229
221-
public function __construct(RequestStack $requestStack, SessionStorageFactoryInterface $storageFactory, callable $usageReporter, NamespacedAttributeBag $sessionAttributes)
222-
{
223-
$this->requestStack = $requestStack;
224-
$this->storageFactory = $storageFactory;
225-
$this->usageReporter = $usageReporter;
226-
$this->sessionAttributes = $sessionAttributes;
227-
}
230+
use Symfony\Component\HttpFoundation\Session\Attribute\NamespacedAttributeBag;
231+
use Symfony\Component\HttpFoundation\Session\Session;
228232
229-
public function createSession(): SessionInterface
230-
{
231-
return new Session(
232-
$this->storageFactory->createStorage($this->requestStack->getMainRequest()),
233-
$this->sessionAttributes,
234-
null,
235-
$this->usageReporter
236-
);
237-
}
238-
}
233+
return function(ContainerConfigurator $configurator) {
234+
$services = $configurator->services();
235+
236+
$services->set('session', Session::class)
237+
->public()
238+
->args([
239+
ref('session.storage'),
240+
ref('session.namespacedattributebag'),
241+
ref('session.flash_bag'),
242+
])
243+
;
244+
245+
$services->set('session.namespacedattributebag', NamespacedAttributeBag::class);
246+
};
239247
240248
.. _session-avoid-start:
241249

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)