1 <?php 
declare(strict_types
=1); 
   4  * this file is part of the rapsys packbundle package. 
   6  * (c) raphaël gertz <symfony@rapsys.eu> 
   8  * for the full copyright and license information, please view the license 
   9  * file that was distributed with this source code. 
  12 namespace Rapsys\UserBundle\Entity
; 
  14 use Doctrine\Common\Collections\ArrayCollection
; 
  15 use Symfony\Component\Security\Core\User\UserInterface
; 
  17 use Rapsys\UserBundle\Entity\Civility
; 
  18 use Rapsys\UserBundle\Entity\Group
; 
  23 class User 
implements UserInterface
, \Serializable 
{ 
  80          * @var ArrayCollection 
  87          * @param string $mail The user mail 
  89         public function __construct(string $mail) { 
  91                 $this->active 
= false; 
  92                 $this->disabled 
= false; 
  93                 $this->groups 
= new ArrayCollection(); 
 101         public function getId(): int { 
 108          * @param string $mail 
 112         public function setMail(string $mail): User 
{ 
 123         public function getMail(): ?string { 
 130          * @param string $pseudonym 
 134         public function setPseudonym(string $pseudonym): User 
{ 
 135                 $this->pseudonym 
= $pseudonym; 
 145         public function getPseudonym(): ?string { 
 146                 return $this->pseudonym
; 
 152          * @param string $forename 
 156         public function setForename(string $forename): User 
{ 
 157                 $this->forename 
= $forename; 
 167         public function getForename(): ?string { 
 168                 return $this->forename
; 
 174          * @param string $surname 
 178         public function setSurname(string $surname): User 
{ 
 179                 $this->surname 
= $surname; 
 189         public function getSurname(): ?string { 
 190                 return $this->surname
; 
 196          * @param string $password 
 200         public function setPassword(string $password): User 
{ 
 201                 $this->password 
= $password; 
 213         public function getPassword(): ?string { 
 214                 return $this->password
; 
 220          * @param bool $active 
 224         public function setActive(bool $active): User 
{ 
 225                 $this->active 
= $active; 
 235         public function getActive(): bool { 
 236                 return $this->active
; 
 242          * @param bool $disabled 
 246         public function setDisabled(bool $disabled): User 
{ 
 247                 $this->disabled 
= $disabled; 
 257         public function getDisabled(): bool { 
 258                 return $this->disabled
; 
 264          * @param \DateTime $created 
 268         public function setCreated(\DateTime 
$created): User 
{ 
 269                 $this->created 
= $created; 
 279         public function getCreated(): \DateTime 
{ 
 280                 return $this->created
; 
 286          * @param \DateTime $updated 
 290         public function setUpdated(\DateTime 
$updated): User 
{ 
 291                 $this->updated 
= $updated; 
 301         public function getUpdated(): \DateTime 
{ 
 302                 return $this->updated
; 
 308         public function setCivility(Civility 
$civility): User 
{ 
 309                 $this->civility 
= $civility; 
 317         public function getCivility(): ?Civility 
{ 
 318                 return $this->civility
; 
 324          * @param Group $group 
 328         public function addGroup(Group 
$group) { 
 329                 $this->groups
[] = $group; 
 337          * @param Group $group 
 339         public function removeGroup(Group 
$group) { 
 340                 $this->groups
->removeElement($group); 
 346          * @return ArrayCollection 
 348         public function getGroups(): ArrayCollection 
{ 
 349                 return $this->groups
; 
 355         public function getRoles(): array { 
 356                 //Get the unique roles list by id 
 357                 return array_unique(array_reduce( 
 358                         //Cast groups as array 
 359                         $this->groups
->toArray(), 
 360                         //Reduce to an array of id => group tuples 
 361                         function ($array, $group) { 
 362                                 $array[$group->getId()] = $group->getRole(); 
 365                         //Init with empty array 
 366                         //XXX: on registration, add each group present in rapsys_user.default.group array to user 
 367                         //XXX: see vendor/rapsys/userbundle/Controller/DefaultController.php +450 
 375         public function getRole(): ?string { 
 377                 $roles = $this->getRoles(); 
 379                 //With roles array empty 
 385                 //Return the role with max id 
 386                 //XXX: should be rewriten if it change in your configuration 
 387                 return $roles[array_reduce( 
 389                         function($cur, $id) { 
 390                                 if ($cur === null || $id > $cur) { 
 402         public function getSalt(): ?string { 
 403                 //No salt required with bcrypt 
 410         public function getUsername(): string { 
 417         public function eraseCredentials(): void {} 
 419         public function serialize(): string { 
 431         public function unserialize($serialized) { 
 440                 ) = unserialize($serialized); 
 444          * Check if account is activated 
 446          * It was from deprecated AdvancedUserInterface, see if it's used anymore 
 448          * @see vendor/symfony/security-core/User/AdvancedUserInterface.php 
 450         public function isActivated(): bool { 
 451                 return $this->active
; 
 455          * Check if account is disabled 
 457          * It was from deprecated AdvancedUserInterface, see if it's used anymore 
 459          * @see vendor/symfony/security-core/User/AdvancedUserInterface.php 
 461         public function isDisabled(): bool { 
 462                 return $this->disabled
; 
 468         public function preUpdate(\Doctrine\ORM\Event\PreUpdateEventArgs 
$eventArgs) { 
 469                 //Check that we have an user instance 
 470                 if (($user = $eventArgs->getEntity()) instanceof User
) { 
 472                         $user->setUpdated(new \
DateTime('now')); 
 477          * Returns a string representation of the user 
 481         public function __toString(): string { 
 482                 return $this->civility
.' '.$this->forename
.' '.$this->surname
;