vendor/bigidea/identity-bundle/Entity/PersonalAccessToken.php line 10

Open in your IDE?
  1. <?php
  2. namespace BigIdea\IdentityBundle\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use DateTimeImmutable;
  5. #[ORM\Entity]
  6. #[ORM\Table(name: 'identity_personal_access_tokens')]
  7. /** @final */ class PersonalAccessToken
  8. {
  9.     #[ORM\Id, ORM\Column(name: "id", type: "integer"), ORM\GeneratedValue(strategy: "AUTO")]
  10.     private int $id;
  11.     #[ORM\ManyToOne(targetEntity: TeamMate::class, inversedBy: "accessTokens")]
  12.     private TeamMate $owner;
  13.     #[ORM\Column(name: "token_value", type: "string", length: 64, unique: true)]
  14.     private string $tokenValue;
  15.     #[ORM\Column(name: "display_name", type: "string", length: 64)]
  16.     private string $displayName;
  17.     #[ORM\Column(name: "not_before", type: "datetimetz_immutable", nullable: true)]
  18.     private ?DateTimeImmutable $notBefore;
  19.     #[ORM\Column(name: "expiry", type: "datetimetz_immutable", nullable: true)]
  20.     private ?DateTimeImmutable $expiry;
  21.     #[ORM\Column(name: "is_enabled", type: "boolean")]
  22.     private bool $enabled;
  23.     public function __construct(TeamMate $owner, string $tokenValue, string $displayName, ?DateTimeImmutable $notBefore, ?DateTimeImmutable $expiry)
  24.     {
  25.         $this->owner = $owner;
  26.         $this->tokenValue = $tokenValue;
  27.         $this->displayName = $displayName;
  28.         $this->notBefore = $notBefore;
  29.         $this->expiry = $expiry;
  30.         $this->enabled = true;
  31.     }
  32.     public function getOwner(): TeamMate
  33.     {
  34.         return $this->owner;
  35.     }
  36.     public function getTokenValue(): string
  37.     {
  38.         return $this->tokenValue;
  39.     }
  40.     public function getNotBefore(): ?DateTimeImmutable
  41.     {
  42.         return $this->notBefore;
  43.     }
  44.     public function getExpiry(): ?DateTimeImmutable
  45.     {
  46.         return $this->expiry;
  47.     }
  48.     public function isActive(): bool
  49.     {
  50.         return $this->enabled;
  51.     }
  52.     public function revoke(): bool
  53.     {
  54.         if (!$this->enabled) {
  55.             return false;
  56.         }
  57.         $this->enabled = false;
  58.         return true;
  59.     }
  60. }