Last active
August 29, 2015 14:04
-
-
Save tobalsan/4ec49540aad087130c9d to your computer and use it in GitHub Desktop.
Symfony2: Custom equals method in user entity to refresh roles
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Just change the "equals" method of your User class like the following to enable automatic roles refresh instead of having to logout / login for roles change to take effect | |
class User implements UserInterface | |
{ | |
// ... | |
/** | |
* Compares this user to another to determine if they are the same. | |
* | |
* @param UserInterface $user | |
* @return boolean True if equal, false otherwise. | |
*/ | |
public function equals(UserInterface $user) | |
{ | |
return | |
md5($user->getUsername()) == md5($this->getUsername()) && | |
md5(serialize($user->getRoles())) == md5(serialize($this->getRoles())); | |
} | |
// ... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment