RVRNEXT-2 add database accessors for oauth tokens

This commit is contained in:
bence committed 2023-04-08 19:08:15 +02:00
1 parent 13b62c8c02
commit 89c7d3b0ea
2 files changed
+143

No files matched your search

+38
View File
@@ -0,0 +1,38 @@
<?php namespace RVR\Repository;
use DateTime;
use Generator;
use SokoWeb\Database\Query\Select;
use RVR\PersistentData\Model\OAuthToken;
use SokoWeb\PersistentData\PersistentDataManager;
class OAuthTokenRepository
{
private PersistentDataManager $pdm;
public function __construct()
{
$this->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);
}
}