@@ -66,16 +66,11 @@ if you type-hint an argument with :class:`Symfony\\Component\\HttpFoundation\\Re
66
66
67
67
.. code-block :: php-standalone
68
68
69
- use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag;
70
69
use Symfony\Component\HttpFoundation\Session\Session;
71
- use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage;
72
70
73
71
$session = new Session();
74
72
$session->start();
75
73
76
- // Pass a storage and a bag implementation explicitely
77
- $session = new Session(new NativeSessionStorage(), new AttributeBag());
78
-
79
74
From a Symfony controller, type-hint an argument with
80
75
:class: `Symfony\\ Component\\ HttpFoundation\\ RequestStack ` or
81
76
:class: `Symfony\\ Component\\ HttpFoundation\\ Request `::
@@ -336,6 +331,19 @@ configuration <config-framework-session>` in
336
331
;
337
332
};
338
333
334
+ .. code-block :: php-standalone
335
+
336
+ use Symfony\Component\HttpFoundation\Cookie;
337
+ use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag;
338
+ use Symfony\Component\HttpFoundation\Session\Session;
339
+ use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage;
340
+
341
+ $storage = new NativeSessionStorage([
342
+ 'cookie_secure' => 'auto',
343
+ 'cookie_samesite' => Cookie::SAMESITE_LAX,
344
+ ]);
345
+ $session = new Session($storage);
346
+
339
347
Setting the ``handler_id `` config option to ``null `` means that Symfony will
340
348
use the native PHP session mechanism. The session metadata files will be stored
341
349
outside of the Symfony application, in a directory controlled by PHP. Although
@@ -390,6 +398,18 @@ session metadata files:
390
398
;
391
399
};
392
400
401
+ .. code-block :: php-standalone
402
+
403
+ use Symfony\Component\HttpFoundation\Cookie;
404
+ use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag;
405
+ use Symfony\Component\HttpFoundation\Session\Session;
406
+ use Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeFileSessionHandler;
407
+ use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage;
408
+
409
+ $handler = new NativeFileSessionHandler('/var/sessions');
410
+ $storage = new NativeSessionStorage([], $handler);
411
+ $session = new Session($storage);
412
+
393
413
Check out the Symfony config reference to learn more about the other available
394
414
:ref: `Session configuration options <config-framework-session >`.
395
415
0 commit comments