'Edit user', self::SCOPE_PROJECT_CREATE => 'Create project', self::SCOPE_PROJECT_EDIT => 'Edit project', ]; #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column] private ?int $id = null; #[ORM\ManyToOne(inversedBy: 'apiTokens')] #[ORM\JoinColumn(nullable: false)] private ?User $ownedBy = null; #[ORM\Column(nullable: true)] private ?\DateTimeImmutable $expiresAt = null; #[ORM\Column(length: 68)] private ?string $token = null; #[ORM\Column] private array $scopes = []; /** * @throws RandomException */ public function __construct(string $tokenType = self::PERSONAL_ACCESS_TOKEN_PREFIX) { $this->token = $tokenType . bin2hex(random_bytes(32)); } public function getId(): ?int { return $this->id; } public function getOwnedBy(): ?User { return $this->ownedBy; } public function setOwnedBy(?User $ownedBy): static { $this->ownedBy = $ownedBy; return $this; } public function getExpiresAt(): ?\DateTimeImmutable { return $this->expiresAt; } public function setExpiresAt(?\DateTimeImmutable $expiresAt): static { $this->expiresAt = $expiresAt; return $this; } public function getToken(): ?string { return $this->token; } public function setToken(string $token): static { $this->token = $token; return $this; } public function getScopes(): array { return $this->scopes; } public function setScopes(array $scopes): static { $this->scopes = $scopes; return $this; } public function isValid(): bool { return $this->expiresAt === null || $this->expiresAt > new \DateTimeImmutable(); } }