vendor/nellapp/sdk-bundle/src/Auth/Entity/Token.php line 17

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the nellapp-core package.
  4.  *
  5.  * (c) Benjamin Georgeault
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Nellapp\Bundle\SDKBundle\Auth\Entity;
  11. use Doctrine\ORM\Mapping as ORM;
  12. #[ORM\Embeddable]
  13. class Token implements \Serializable
  14. {
  15.     #[ORM\Column(type'text'nullabletrue)]
  16.     private ?string $token null;
  17.     #[ORM\Column(type'datetime'nullabletrue)]
  18.     private ?\DateTimeInterface $expireAt null;
  19.     #[ORM\Column(type'text'nullabletrue)]
  20.     private ?string $refreshToken null;
  21.     public function getToken(): ?string
  22.     {
  23.         return $this->token;
  24.     }
  25.     public function setToken(?string $token): static
  26.     {
  27.         $this->token $token;
  28.         return $this;
  29.     }
  30.     public function getExpireAt(): ?\DateTimeInterface
  31.     {
  32.         return $this->expireAt;
  33.     }
  34.     public function setExpireAt(?\DateTimeInterface $expireAt): static
  35.     {
  36.         $this->expireAt $expireAt;
  37.         return $this;
  38.     }
  39.     public function isExpired(): bool
  40.     {
  41.         if (null === $expireAt $this->getExpireAt()) {
  42.             return false;
  43.         }
  44.         return $expireAt->getTimestamp() < time();
  45.     }
  46.     public function getRefreshToken(): ?string
  47.     {
  48.         return $this->refreshToken;
  49.     }
  50.     public function setRefreshToken(?string $refreshToken): static
  51.     {
  52.         $this->refreshToken $refreshToken;
  53.         return $this;
  54.     }
  55.     public function serialize()
  56.     {
  57.         return serialize([
  58.             $this->token,
  59.             $this->expireAt,
  60.             $this->refreshToken,
  61.         ]);
  62.     }
  63.     public function unserialize($data)
  64.     {
  65.         list(
  66.             $this->token,
  67.             $this->expireAt,
  68.             $this->refreshToken,
  69.         ) = unserialize($data);
  70.     }
  71. }