vendor/contao/core-bundle/src/Entity/RememberMe.php line 32

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4.  * This file is part of Contao.
  5.  *
  6.  * (c) Leo Feyer
  7.  *
  8.  * @license LGPL-3.0-or-later
  9.  */
  10. namespace Contao\CoreBundle\Entity;
  11. use Doctrine\ORM\Mapping as ORM;
  12. use Doctrine\ORM\Mapping\GeneratedValue;
  13. use Doctrine\ORM\Mapping\UniqueConstraint;
  14. use Symfony\Component\Security\Core\User\UserInterface;
  15. /**
  16.  * @ORM\Table(
  17.  *     name="tl_remember_me",
  18.  *     indexes={
  19.  *         @ORM\Index(name="series", columns={"series"})
  20.  *     },
  21.  *     uniqueConstraints={
  22.  *        @UniqueConstraint(name="value", columns={"value"})
  23.  *    }
  24.  * )
  25.  * @ORM\Entity(repositoryClass="Contao\CoreBundle\Repository\RememberMeRepository")
  26.  */
  27. class RememberMe
  28. {
  29.     /**
  30.      * @ORM\Id
  31.      * @ORM\Column(type="integer", options={"unsigned"=true})
  32.      * @GeneratedValue
  33.      */
  34.     protected int $id;
  35.     /**
  36.      * @ORM\Column(type="binary_string", length=32, nullable=false, options={"fixed"=true})
  37.      */
  38.     protected string $series;
  39.     /**
  40.      * @ORM\Column(type="binary_string", length=64, nullable=false, options={"fixed"=true})
  41.      */
  42.     protected string $value;
  43.     /**
  44.      * @ORM\Column(type="datetime", nullable=false)
  45.      */
  46.     protected \DateTimeInterface $lastUsed;
  47.     /**
  48.      * @ORM\Column(type="datetime", nullable=true)
  49.      */
  50.     protected ?\DateTimeInterface $expires null;
  51.     /**
  52.      * @ORM\Column(type="string", length=100, nullable=false)
  53.      */
  54.     protected string $class;
  55.     /**
  56.      * @ORM\Column(type="string", length=200, nullable=false)
  57.      */
  58.     protected string $username;
  59.     public function __construct(UserInterface $userstring $series)
  60.     {
  61.         $this->class = \get_class($user);
  62.         $this->series $series;
  63.         $this->value random_bytes(64);
  64.         $this->username $user->getUserIdentifier();
  65.         $this->lastUsed = new \DateTime();
  66.         $this->expires null;
  67.     }
  68.     public function __clone()
  69.     {
  70.         $this->value '';
  71.         $this->lastUsed = new \DateTime();
  72.         $this->expires null;
  73.     }
  74.     public function getSeries(): string
  75.     {
  76.         return $this->series;
  77.     }
  78.     public function getValue(): string
  79.     {
  80.         return $this->value;
  81.     }
  82.     public function getLastUsed(): \DateTimeInterface
  83.     {
  84.         return $this->lastUsed;
  85.     }
  86.     public function getExpires(): ?\DateTimeInterface
  87.     {
  88.         return $this->expires;
  89.     }
  90.     public function setExpiresInSeconds(int $seconds): self
  91.     {
  92.         if (null === $this->expires) {
  93.             $this->expires = (new \DateTime())->add(new \DateInterval('PT'.$seconds.'S'));
  94.         }
  95.         return $this;
  96.     }
  97.     public function getClass(): string
  98.     {
  99.         return $this->class;
  100.     }
  101.     public function getUsername(): string
  102.     {
  103.         return $this->username;
  104.     }
  105.     public function cloneWithNewValue(): self
  106.     {
  107.         $clone = clone $this;
  108.         $clone->value random_bytes(64);
  109.         return $clone;
  110.     }
  111. }