Skip to content

Commit 73a02c2

Browse files
ThomasLandauerjaviereguiluz
authored andcommitted
Update sessions.rst
First step to explain how to activate Namespaced Attributes, as requested by #7378
1 parent de932b0 commit 73a02c2

File tree

1 file changed

+40
-23
lines changed

1 file changed

+40
-23
lines changed

components/http_foundation/sessions.rst

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,33 @@ and remember me login settings or other user based state information.
181181
:class:`Symfony\\Component\\HttpFoundation\\Session\\Attribute\\NamespacedAttributeBag`
182182
This implementation allows for attributes to be stored in a structured namespace.
183183

184+
:class:`Symfony\\Component\\HttpFoundation\\Session\\Attribute\\AttributeBagInterface`
185+
has a simple API
186+
187+
:method:`Symfony\\Component\\HttpFoundation\\Session\\Attribute\\AttributeBagInterface::set`
188+
Sets an attribute by key.
189+
190+
:method:`Symfony\\Component\\HttpFoundation\\Session\\Attribute\\AttributeBagInterface::get`
191+
Gets an attribute by key.
192+
193+
:method:`Symfony\\Component\\HttpFoundation\\Session\\Attribute\\AttributeBagInterface::all`
194+
Gets all attributes as an array of key => value.
195+
196+
:method:`Symfony\\Component\\HttpFoundation\\Session\\Attribute\\AttributeBagInterface::has`
197+
Returns true if the attribute exists.
198+
199+
:method:`Symfony\\Component\\HttpFoundation\\Session\\Attribute\\AttributeBagInterface::replace`
200+
Sets multiple attributes at once: takes a keyed array and sets each key => value pair.
201+
202+
:method:`Symfony\\Component\\HttpFoundation\\Session\\Attribute\\AttributeBagInterface::remove`
203+
Deletes an attribute by key.
204+
205+
:method:`Symfony\\Component\\HttpFoundation\\Session\\Attribute\\AttributeBagInterface::clear`
206+
Clear the bag.
207+
208+
Namespaced Attributes
209+
.....................
210+
184211
Any plain key-value storage system is limited in the extent to which
185212
complex data can be stored since each key must be unique. You can achieve
186213
namespacing by introducing a naming convention to the keys so different parts of
@@ -211,29 +238,19 @@ structure like this using a namespace character (defaults to ``/``)::
211238

212239
This way you can easily access a key within the stored array directly and easily.
213240

214-
:class:`Symfony\\Component\\HttpFoundation\\Session\\Attribute\\AttributeBagInterface`
215-
has a simple API
216-
217-
:method:`Symfony\\Component\\HttpFoundation\\Session\\Attribute\\AttributeBagInterface::set`
218-
Sets an attribute by key.
219-
220-
:method:`Symfony\\Component\\HttpFoundation\\Session\\Attribute\\AttributeBagInterface::get`
221-
Gets an attribute by key.
222-
223-
:method:`Symfony\\Component\\HttpFoundation\\Session\\Attribute\\AttributeBagInterface::all`
224-
Gets all attributes as an array of key => value.
225-
226-
:method:`Symfony\\Component\\HttpFoundation\\Session\\Attribute\\AttributeBagInterface::has`
227-
Returns true if the attribute exists.
228-
229-
:method:`Symfony\\Component\\HttpFoundation\\Session\\Attribute\\AttributeBagInterface::replace`
230-
Sets multiple attributes at once: takes a keyed array and sets each key => value pair.
231-
232-
:method:`Symfony\\Component\\HttpFoundation\\Session\\Attribute\\AttributeBagInterface::remove`
233-
Deletes an attribute by key.
234-
235-
:method:`Symfony\\Component\\HttpFoundation\\Session\\Attribute\\AttributeBagInterface::clear`
236-
Clear the bag.
241+
To activate Namespaced Attributes, add this to your `services.yml`::
242+
243+
# app/config/services.yml
244+
245+
services:
246+
session:
247+
class: Symfony\Component\HttpFoundation\Session\Session
248+
arguments:
249+
- @session.storage
250+
- @your.session.attribute_bag #service id is defined below
251+
- @session.flash_bag
252+
your.session.attribute_bag:
253+
class: Symfony\Component\HttpFoundation\Session\Attribute\NamespacedAttributeBag
237254

238255
Flash Messages
239256
~~~~~~~~~~~~~~

0 commit comments

Comments
 (0)