<?php
namespace BigIdea\IdentityBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use DateTimeImmutable;
#[ORM\Entity]
#[ORM\Table(name: 'identity_personal_access_tokens')]
/** @final */ class PersonalAccessToken
{
#[ORM\Id, ORM\Column(name: "id", type: "integer"), ORM\GeneratedValue(strategy: "AUTO")]
private int $id;
#[ORM\ManyToOne(targetEntity: TeamMate::class, inversedBy: "accessTokens")]
private TeamMate $owner;
#[ORM\Column(name: "token_value", type: "string", length: 64, unique: true)]
private string $tokenValue;
#[ORM\Column(name: "display_name", type: "string", length: 64)]
private string $displayName;
#[ORM\Column(name: "not_before", type: "datetimetz_immutable", nullable: true)]
private ?DateTimeImmutable $notBefore;
#[ORM\Column(name: "expiry", type: "datetimetz_immutable", nullable: true)]
private ?DateTimeImmutable $expiry;
#[ORM\Column(name: "is_enabled", type: "boolean")]
private bool $enabled;
public function __construct(TeamMate $owner, string $tokenValue, string $displayName, ?DateTimeImmutable $notBefore, ?DateTimeImmutable $expiry)
{
$this->owner = $owner;
$this->tokenValue = $tokenValue;
$this->displayName = $displayName;
$this->notBefore = $notBefore;
$this->expiry = $expiry;
$this->enabled = true;
}
public function getOwner(): TeamMate
{
return $this->owner;
}
public function getTokenValue(): string
{
return $this->tokenValue;
}
public function getNotBefore(): ?DateTimeImmutable
{
return $this->notBefore;
}
public function getExpiry(): ?DateTimeImmutable
{
return $this->expiry;
}
public function isActive(): bool
{
return $this->enabled;
}
public function revoke(): bool
{
if (!$this->enabled) {
return false;
}
$this->enabled = false;
return true;
}
}