diff --git a/src/PersistentData/Model/OAuthToken.php b/src/PersistentData/Model/OAuthToken.php new file mode 100644 index 0000000..2cf5456 --- /dev/null +++ b/src/PersistentData/Model/OAuthToken.php @@ -0,0 +1,105 @@ + User::class]; + + private string $nonce = ''; + + private ?User $user = null; + + private ?int $userId = null; + + private string $code = ''; + + private DateTime $created; + + private DateTime $expires; + + public function setNonce(string $nonce): void + { + $this->nonce = $nonce; + } + + public function setUser(User $user): void + { + $this->user = $user; + } + + public function setUserId(int $userId): void + { + $this->userId = $userId; + } + + public function setCode(string $code): void + { + $this->code = $code; + } + + public function setCreatedDate(DateTime $created): void + { + $this->created = $created; + } + + public function setExpiresDate(DateTime $expires): void + { + $this->expires = $expires; + } + + public function setCreated(string $created): void + { + $this->created = new DateTime($created); + } + + public function setExpires(string $expires): void + { + $this->expires = new DateTime($expires); + } + + public function getNonce(): string + { + return $this->nonce; + } + + public function getUser(): ?User + { + return $this->user; + } + + public function getUserId(): ?int + { + return $this->userId; + } + + public function getCode(): string + { + return $this->code; + } + + public function getCreatedDate(): DateTime + { + return $this->created; + } + + public function getCreated(): string + { + return $this->created->format('Y-m-d H:i:s'); + } + + public function getExpiresDate(): DateTime + { + return $this->expires; + } + + public function getExpires(): string + { + return $this->expires->format('Y-m-d H:i:s'); + } +} diff --git a/src/Repository/OAuthTokenRepository.php b/src/Repository/OAuthTokenRepository.php new file mode 100644 index 0000000..6898a3a --- /dev/null +++ b/src/Repository/OAuthTokenRepository.php @@ -0,0 +1,38 @@ +pdm = new PersistentDataManager(); + } + + public function getById(int $id): ?OAuthToken + { + return $this->pdm->selectFromDbById($id, OAuthToken::class); + } + + public function getByCode(string $code): ?OAuthToken + { + $select = new Select(\Container::$dbConnection); + $select->where('code', '=', $code); + + return $this->pdm->selectFromDb($select, OAuthToken::class); + } + + public function getAllExpired(): Generator + { + $select = new Select(\Container::$dbConnection); + $select->where('expires', '<', (new DateTime())->format('Y-m-d H:i:s')); + + yield from $this->pdm->selectMultipleFromDb($select, OAuthToken::class); + } +}