Skip to content

Commit 45612ad

Browse files
xabbuhweaverryan
authored andcommitted
improve the serialization of custom user models
(cherry picked from commit 7b34eab)
1 parent 26881d5 commit 45612ad

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

cookbook/security/entity_provider.rst

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,9 @@ focus on the most important methods that come from the
149149
{
150150
return serialize(array(
151151
$this->id,
152+
$this->username,
153+
$this->salt,
154+
$this->password,
152155
));
153156
}
154157
@@ -159,10 +162,20 @@ focus on the most important methods that come from the
159162
{
160163
list (
161164
$this->id,
165+
$this->username,
166+
$this->salt,
167+
$this->password,
162168
) = unserialize($serialized);
163169
}
164170
}
165171
172+
.. note::
173+
174+
When implementing the
175+
:class:`Symfony\\Component\\Security\\Core\\User\\EquatableInterface`,
176+
you determine yourself which properties need to be compared to distinguish
177+
your user objects.
178+
166179
.. tip::
167180

168181
:ref:`Generate the database table <book-doctrine-creating-the-database-tables-schema>`
@@ -573,7 +586,7 @@ methods have changed::
573586
class User implements AdvancedUserInterface, \Serializable
574587
{
575588
// ...
576-
589+
577590
/**
578591
* @ORM\ManyToMany(targetEntity="Role", inversedBy="users")
579592
*
@@ -589,7 +602,7 @@ methods have changed::
589602
{
590603
return $this->roles->toArray();
591604
}
592-
605+
593606
// ...
594607
595608
}
@@ -646,7 +659,7 @@ of the application::
646659
{
647660
return $this->role;
648661
}
649-
662+
650663
// ... getters and setters for each property
651664
}
652665

0 commit comments

Comments
 (0)