@@ -171,7 +171,7 @@ focus on the most important methods that come from the
171
171
172
172
.. note ::
173
173
174
- When implementing the
174
+ If you choose to implement
175
175
:class: `Symfony\\ Component\\ Security\\ Core\\ User\\ EquatableInterface `,
176
176
you determine yourself which properties need to be compared to distinguish
177
177
your user objects.
@@ -198,14 +198,27 @@ interface forces the class to implement the five following methods:
198
198
199
199
For more details on each of these, see :class: `Symfony\\ Component\\ Security\\ Core\\ User\\ UserInterface `.
200
200
201
- .. note ::
201
+ .. sidebar :: What is the importance of serialize and unserialize?
202
202
203
203
The :phpclass: `Serializable ` interface and its ``serialize `` and ``unserialize ``
204
204
methods have been added to allow the ``User `` class to be serialized
205
205
to the session. This may or may not be needed depending on your setup,
206
- but it's probably a good idea. Only the ``id `` needs to be serialized,
207
- because the :method: `Symfony\\ Bridge\\ Doctrine\\ Security\\ User\\ EntityUserProvider::refreshUser `
208
- method reloads the user on each request by using the ``id ``.
206
+ but it's probably a good idea. The ``id `` is the most important value
207
+ that needs to be serialized because the
208
+ :method: `Symfony\\ Bridge\\ Doctrine\\ Security\\ User\\ EntityUserProvider::refreshUser `
209
+ method reloads the user on each request by using the ``id ``. In practice,
210
+ this means that the User object is reloaded from the database on each
211
+ request using the ``id `` from the serialized object. This makes sure
212
+ all of the User's data is fresh.
213
+
214
+ Symfony also uses the ``username ``, ``salt ``, and ``password `` to verify
215
+ that the User has not changed between requests. Failing to serialize
216
+ these may cause you to be logged out on each request. If your User implements
217
+ :class: `Symfony\\ Component\\ Security\\ Core\\ User\\ EquatableInterface `,
218
+ then instead of these properties being checked, your ``isEqualTo `` method
219
+ is simply called, and you can check whatever properties you want. Unless
220
+ you understand this, you probably *won't * need to implement this interface
221
+ or worry about it.
209
222
210
223
Below is an export of the ``User `` table from MySQL with user ``admin `` and
211
224
password ``admin `` (which has been encoded). For details on how to create
0 commit comments