Skip to content

Commit 6ddc50c

Browse files
committed
Merge pull request #2111 from WouterJ/patch-3
Fixed use of equals (closes #2109)
2 parents 331001c + cf20b16 commit 6ddc50c

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

cookbook/security/custom_provider.rst

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,26 @@ create a ``User`` class that represents that data. The ``User`` can look
2222
however you want and contain any data. The only requirement is that the
2323
class implements :class:`Symfony\\Component\\Security\\Core\\User\\UserInterface`.
2424
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.
2735

2836
Let's see this in action::
2937

3038
// src/Acme/WebserviceUserBundle/Security/User/WebserviceUser.php
3139
namespace Acme\WebserviceUserBundle\Security\User;
3240

3341
use Symfony\Component\Security\Core\User\UserInterface;
42+
use Symfony\Component\Security\Core\User\EquatableInterface;
3443

35-
class WebserviceUser implements UserInterface
44+
class WebserviceUser implements UserInterface, EquatableInterface
3645
{
3746
private $username;
3847
private $password;
@@ -71,7 +80,7 @@ Let's see this in action::
7180
{
7281
}
7382

74-
public function equals(UserInterface $user)
83+
public function isEqualTo(UserInterface $user)
7584
{
7685
if (!$user instanceof WebserviceUser) {
7786
return false;
@@ -93,11 +102,13 @@ Let's see this in action::
93102
}
94103
}
95104

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+
96109
If you have more information about your users - like a "first name" - then
97110
you can add a ``firstName`` field to hold that data.
98111

99-
For more details on each of the methods, see :class:`Symfony\\Component\\Security\\Core\\User\\UserInterface`.
100-
101112
Create a User Provider
102113
----------------------
103114

0 commit comments

Comments
 (0)