47 lines
1.3 KiB
PHP
47 lines
1.3 KiB
PHP
<?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 getByAccessToken(string $accessToken): ?OAuthToken
|
|
{
|
|
$select = new Select(\Container::$dbConnection);
|
|
$select->where('access_token', '=', $accessToken);
|
|
|
|
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);
|
|
}
|
|
}
|