enabled = true; $this->key = $this->generateV4Uuid(); } public function getKey(): string { return $this->key; } public function setKey(string $key): self { $this->key = $key; return $this; } public function getExpirationDate(): ?Chronos { return $this->expirationDate; } public function setExpirationDate(Chronos $expirationDate): self { $this->expirationDate = $expirationDate; return $this; } public function isExpired(): bool { if ($this->expirationDate === null) { return false; } return $this->expirationDate->lt(Chronos::now()); } public function isEnabled(): bool { return $this->enabled; } public function setEnabled(bool $enabled): self { $this->enabled = $enabled; return $this; } public function disable(): self { return $this->setEnabled(false); } /** * Tells if this api key is enabled and not expired */ public function isValid(): bool { return $this->isEnabled() && ! $this->isExpired(); } public function __toString(): string { return $this->getKey(); } }