X-Git-Url: https://git.rapsys.eu/userbundle/blobdiff_plain/60b5bbf626f4aca106b66be539a9b8c4cf71892e..d08d8a1549a2205f39f91fa338ea84fd9bcd2def:/Entity/User.php?ds=sidebyside diff --git a/Entity/User.php b/Entity/User.php index 68b0dcf..82cbcff 100644 --- a/Entity/User.php +++ b/Entity/User.php @@ -14,33 +14,34 @@ namespace Rapsys\UserBundle\Entity; use Doctrine\Common\Collections\Collection; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ORM\Event\PreUpdateEventArgs; -use Symfony\Component\Security\Core\User\UserInterface; -use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface; use Rapsys\UserBundle\Entity\Civility; use Rapsys\UserBundle\Entity\Group; +use Symfony\Component\Security\Core\User\UserInterface; +use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface; + /** * User */ class User implements UserInterface, PasswordAuthenticatedUserInterface { /** - * @var ?integer + * Primary key */ - protected ?int $id; + protected ?int $id = null; /** - * @var \DateTime + * Create datetime */ - protected \DateTime $created; + protected \DateTimeImmutable $created; /** - * @var \DateTime + * Update datetime */ - protected \DateTime $updated; + protected \DateTimeImmutable $updated; /** - * @var Doctrine\Common\Collections\Collection + * Groups collection */ protected Collection $groups; @@ -57,8 +58,8 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface { */ public function __construct(protected string $mail, protected string $password, protected ?Civility $civility = null, protected ?string $forename = null, protected ?string $surname = null, protected bool $active = false, protected bool $enable = true) { //Set defaults - $this->created = new \DateTime('now'); - $this->updated = new \DateTime('now'); + $this->created = new \DateTimeImmutable('now'); + $this->updated = new \DateTimeImmutable('now'); //Set collections $this->groups = new ArrayCollection(); @@ -154,10 +155,10 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface { } /** - * Get password - * * {@inheritdoc} * + * Get password + * * @return string */ public function getPassword(): string { @@ -211,11 +212,11 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface { /** * Set created * - * @param \DateTime $created + * @param \DateTimeImmutable $created * * @return User */ - public function setCreated(\DateTime $created): User { + public function setCreated(\DateTimeImmutable $created): User { $this->created = $created; return $this; @@ -224,9 +225,9 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface { /** * Get created * - * @return \DateTime + * @return \DateTimeImmutable */ - public function getCreated(): \DateTime { + public function getCreated(): \DateTimeImmutable { return $this->created; } @@ -315,7 +316,7 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface { return $array; }, //Init with empty array - //XXX: on registration, add each group present in rapsys_user.default.group array to user + //XXX: on registration, add each group present in rapsysuser.default.group array to user //XXX: see vendor/rapsys/userbundle/Controller/DefaultController.php +450 [] )); @@ -432,7 +433,7 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface { */ public function preUpdate(PreUpdateEventArgs $eventArgs) { //Check that we have an user instance - if (($user = $eventArgs->getEntity()) instanceof User) { + if (($user = $eventArgs->getObject()) instanceof User) { //Set updated value $user->setUpdated(new \DateTime('now')); }