<?php
/*
* This file is part of the nellapp-core package.
*
* (c) Benjamin Georgeault
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Nellapp\Bundle\SDKBundle\Auth\Entity;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Embeddable]
class Token implements \Serializable
{
#[ORM\Column(type: 'text', nullable: true)]
private ?string $token = null;
#[ORM\Column(type: 'datetime', nullable: true)]
private ?\DateTimeInterface $expireAt = null;
#[ORM\Column(type: 'text', nullable: true)]
private ?string $refreshToken = null;
public function getToken(): ?string
{
return $this->token;
}
public function setToken(?string $token): static
{
$this->token = $token;
return $this;
}
public function getExpireAt(): ?\DateTimeInterface
{
return $this->expireAt;
}
public function setExpireAt(?\DateTimeInterface $expireAt): static
{
$this->expireAt = $expireAt;
return $this;
}
public function isExpired(): bool
{
if (null === $expireAt = $this->getExpireAt()) {
return false;
}
return $expireAt->getTimestamp() < time();
}
public function getRefreshToken(): ?string
{
return $this->refreshToken;
}
public function setRefreshToken(?string $refreshToken): static
{
$this->refreshToken = $refreshToken;
return $this;
}
public function serialize()
{
return serialize([
$this->token,
$this->expireAt,
$this->refreshToken,
]);
}
public function unserialize($data)
{
list(
$this->token,
$this->expireAt,
$this->refreshToken,
) = unserialize($data);
}
}