enabled = true; $this->key = $this->generateV4Uuid(); } /** * @return string */ public function getKey() { return $this->key; } /** * @param string $key * @return $this */ public function setKey($key) { $this->key = $key; return $this; } /** * @return \DateTime */ public function getExpirationDate() { return $this->expirationDate; } /** * @param \DateTime $expirationDate * @return $this */ public function setExpirationDate($expirationDate) { $this->expirationDate = $expirationDate; return $this; } /** * @return bool */ public function isExpired() { if (! isset($this->expirationDate)) { return false; } return $this->expirationDate < new \DateTime(); } /** * @return boolean */ public function isEnabled() { return $this->enabled; } /** * @param boolean $enabled * @return $this */ public function setEnabled($enabled) { $this->enabled = $enabled; return $this; } /** * Disables this API key * * @return $this */ public function disable() { return $this->setEnabled(false); } /** * Tells if this api key is enabled and not expired * * @return bool */ public function isValid() { return $this->isEnabled() && ! $this->isExpired(); } }