@@ -22,17 +22,26 @@ create a ``User`` class that represents that data. The ``User`` can look
22
22
however you want and contain any data. The only requirement is that the
23
23
class implements :class: `Symfony\\ Component\\ Security\\ Core\\ User\\ UserInterface `.
24
24
The methods in this interface should therefore be defined in the custom user
25
- class: ``getRoles() ``, ``getPassword() ``, ``getSalt() ``, ``getUsername() ``,
26
- ``eraseCredentials() ``, ``equals() ``.
25
+ class: :method: `Symfony\\ Component\\ Security\\ Core\\ User\\ UserInterface::getRoles `,
26
+ :method`Symfony\\ Component\\ Security\\ Core\\ User\\ UserInterfacegetPassword`,
27
+ :method: `Symfony\\ Component\\ Security\\ Core\\ User\\ UserInterface::getSalt `,
28
+ :method: `Symfony\\ Component\\ Security\\ Core\\ User\\ UserInterface::getUsername `,
29
+ :method: `Symfony\\ Component\\ Security\\ Core\\ User\\ UserInterface::eraseCredentials `.
30
+ It is also usefull to implement the
31
+ :class: `Symfony\\ Component\\ Security\\ Core\\ User\\ EquatableInterface ` interface,
32
+ to define a method how check if the user is equal to the current user. This
33
+ interface requires a :method: `Symfony\\ Component\\ Security\\ Core\\ User\\ EquatableInterface::isEqualTo `
34
+ method.
27
35
28
36
Let's see this in action::
29
37
30
38
// src/Acme/WebserviceUserBundle/Security/User/WebserviceUser.php
31
39
namespace Acme\WebserviceUserBundle\Security\User;
32
40
33
41
use Symfony\Component\Security\Core\User\UserInterface;
42
+ use Symfony\Component\Security\Core\User\EquatableInterface;
34
43
35
- class WebserviceUser implements UserInterface
44
+ class WebserviceUser implements UserInterface, EquatableInterface
36
45
{
37
46
private $username;
38
47
private $password;
@@ -71,7 +80,7 @@ Let's see this in action::
71
80
{
72
81
}
73
82
74
- public function equals (UserInterface $user)
83
+ public function isEqualTo (UserInterface $user)
75
84
{
76
85
if (!$user instanceof WebserviceUser) {
77
86
return false;
@@ -93,11 +102,13 @@ Let's see this in action::
93
102
}
94
103
}
95
104
105
+ .. versionadded :: 2.1
106
+ The ``EquatableInterface `` was added in Symfony 2.1, use the ``equals() ``
107
+ method of the ``UserInterface `` in Symfony 2.0
108
+
96
109
If you have more information about your users - like a "first name" - then
97
110
you can add a ``firstName `` field to hold that data.
98
111
99
- For more details on each of the methods, see :class: `Symfony\\ Component\\ Security\\ Core\\ User\\ UserInterface `.
100
-
101
112
Create a User Provider
102
113
----------------------
103
114
0 commit comments