@@ -348,18 +348,17 @@ Symfony provides a nice session object that you can use to store information
348348about the user between requests. By default, Symfony stores the attributes in a
349349cookie by using native PHP sessions.
350350
351- To retrieve the session, call
352- :method: `Symfony\\ Bundle\\ FrameworkBundle\\ Controller\\ Controller::getSession `
353- method on the ``Request `` object. This method returns a
354- :class: `Symfony\\ Component\\ HttpFoundation\\ Session\\ SessionInterface ` with easy
355- methods for storing and fetching things from the session::
356351
357- use Symfony\Component\HttpFoundation\Request;
352+ .. versionadded :: 3.3
353+ The ability to request a ``Session `` in actions was introduced in Symfony 3.3.
358354
359- public function indexAction(Request $request)
360- {
361- $session = $request->getSession();
355+ To retrieve the session, add the :class: `Symfony\\ Component\\ HttpFoundation\\ Session\\ SessionInterface `
356+ type-hint to your argument and Symfony will provide you with a session::
357+
358+ use Symfony\Component\HttpFoundation\Session\SessionInterface;
362359
360+ public function indexAction(SessionInterface $session)
361+ {
363362 // store an attribute for reuse during a later user request
364363 $session->set('foo', 'bar');
365364
@@ -372,6 +371,11 @@ methods for storing and fetching things from the session::
372371
373372Stored attributes remain in the session for the remainder of that user's session.
374373
374+ .. tip ::
375+
376+ Every ``SessionInterface `` implementation is supported. If you have your
377+ own implementation, type-hint this in the arguments instead.
378+
375379.. index ::
376380 single: Session; Flash messages
377381
0 commit comments