Skip to content

Commit 5254aee

Browse files
committed
Removed some repeated content and minor rewords
1 parent 73a02c2 commit 5254aee

File tree

1 file changed

+21
-37
lines changed

1 file changed

+21
-37
lines changed

components/http_foundation/sessions.rst

Lines changed: 21 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -94,29 +94,12 @@ Session Workflow
9494
Session Attributes
9595
..................
9696

97-
:method:`Symfony\\Component\\HttpFoundation\\Session\\Session::set`
98-
Sets an attribute by key.
97+
The session attributes are stored internally in a "Bag", a PHP object that acts
98+
like an array. They can be set, removed, checked, etc. using the methods
99+
explained later in this article for the ``AttributeBagInterface`` class. See
100+
:ref:`attribute-bag-interface`.
99101

100-
:method:`Symfony\\Component\\HttpFoundation\\Session\\Session::get`
101-
Gets an attribute by key.
102-
103-
:method:`Symfony\\Component\\HttpFoundation\\Session\\Session::all`
104-
Gets all attributes as an array of key => value.
105-
106-
:method:`Symfony\\Component\\HttpFoundation\\Session\\Session::has`
107-
Returns true if the attribute exists.
108-
109-
:method:`Symfony\\Component\\HttpFoundation\\Session\\Session::replace`
110-
Sets multiple attributes at once: takes a keyed array and sets each key => value pair.
111-
112-
:method:`Symfony\\Component\\HttpFoundation\\Session\\Session::remove`
113-
Deletes an attribute by key.
114-
115-
:method:`Symfony\\Component\\HttpFoundation\\Session\\Session::clear`
116-
Clear all attributes.
117-
118-
The attributes are stored internally in a "Bag", a PHP object that acts like
119-
an array. A few methods exist for "Bag" management:
102+
In addition, a few methods exist for "Bag" management:
120103

121104
:method:`Symfony\\Component\\HttpFoundation\\Session\\Session::registerBag`
122105
Registers a :class:`Symfony\\Component\\HttpFoundation\\Session\\SessionBagInterface`.
@@ -168,12 +151,14 @@ the following API which is intended mainly for internal purposes:
168151
:method:`Symfony\\Component\\HttpFoundation\\Session\\SessionBagInterface::getName`
169152
Returns the name of the session bag.
170153

154+
.. _attribute-bag-interface:
155+
171156
Attributes
172157
~~~~~~~~~~
173158

174159
The purpose of the bags implementing the :class:`Symfony\\Component\\HttpFoundation\\Session\\Attribute\\AttributeBagInterface`
175160
is to handle session attribute storage. This might include things like user ID,
176-
and remember me login settings or other user based state information.
161+
and "Remember Me" login settings or other user based state information.
177162

178163
:class:`Symfony\\Component\\HttpFoundation\\Session\\Attribute\\AttributeBag`
179164
This is the standard default implementation.
@@ -185,25 +170,27 @@ and remember me login settings or other user based state information.
185170
has a simple API
186171

187172
:method:`Symfony\\Component\\HttpFoundation\\Session\\Attribute\\AttributeBagInterface::set`
188-
Sets an attribute by key.
173+
Sets an attribute by name (``set('name', 'value')``).
189174

190175
:method:`Symfony\\Component\\HttpFoundation\\Session\\Attribute\\AttributeBagInterface::get`
191-
Gets an attribute by key.
176+
Gets an attribute by name (``get('name')``) and can define a default
177+
value when the attribute doesn't exist (``get('name', 'default_value')``).
192178

193179
:method:`Symfony\\Component\\HttpFoundation\\Session\\Attribute\\AttributeBagInterface::all`
194-
Gets all attributes as an array of key => value.
180+
Gets all attributes as an associative array of ``name => value``.
195181

196182
:method:`Symfony\\Component\\HttpFoundation\\Session\\Attribute\\AttributeBagInterface::has`
197-
Returns true if the attribute exists.
183+
Returns ``true`` if the attribute exists.
198184

199185
:method:`Symfony\\Component\\HttpFoundation\\Session\\Attribute\\AttributeBagInterface::replace`
200-
Sets multiple attributes at once: takes a keyed array and sets each key => value pair.
186+
Sets multiple attributes at once using an associative array (``name => value``).
187+
If the attributes existed, they are replaced; if not, they are created.
201188

202189
:method:`Symfony\\Component\\HttpFoundation\\Session\\Attribute\\AttributeBagInterface::remove`
203-
Deletes an attribute by key.
190+
Deletes an attribute by name.
204191

205192
:method:`Symfony\\Component\\HttpFoundation\\Session\\Attribute\\AttributeBagInterface::clear`
206-
Clear the bag.
193+
Deletes all attributes.
207194

208195
Namespaced Attributes
209196
.....................
@@ -232,24 +219,21 @@ the array::
232219
$session->set('tokens', $tokens);
233220

234221
With structured namespacing, the key can be translated to the array
235-
structure like this using a namespace character (defaults to ``/``)::
222+
structure like this using a namespace character (which defaults to ``/``)::
236223

237224
$session->set('tokens/c', $value);
238225

239-
This way you can easily access a key within the stored array directly and easily.
240-
241-
To activate Namespaced Attributes, add this to your `services.yml`::
226+
To activate namespaced attributes, add this to your ``services.yml``::
242227

243228
# app/config/services.yml
244-
245229
services:
246230
session:
247231
class: Symfony\Component\HttpFoundation\Session\Session
248232
arguments:
249233
- @session.storage
250-
- @your.session.attribute_bag #service id is defined below
234+
- @app.session.attribute_bag # this service id is defined below
251235
- @session.flash_bag
252-
your.session.attribute_bag:
236+
app.session.attribute_bag:
253237
class: Symfony\Component\HttpFoundation\Session\Attribute\NamespacedAttributeBag
254238

255239
Flash Messages

0 commit comments

Comments
 (0)