55 lines
1.5 KiB
PHP
55 lines
1.5 KiB
PHP
<?php namespace RVR\Repository;
|
|
|
|
use SokoWeb\Interfaces\Repository\IUserRepository;
|
|
use SokoWeb\Database\Query\Select;
|
|
use RVR\PersistentData\Model\User;
|
|
use SokoWeb\PersistentData\PersistentDataManager;
|
|
|
|
class UserRepository implements IUserRepository
|
|
{
|
|
private PersistentDataManager $pdm;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->pdm = new PersistentDataManager();
|
|
}
|
|
|
|
public function getById(int $userId): ?User
|
|
{
|
|
return $this->pdm->selectFromDbById($userId, User::class);
|
|
}
|
|
|
|
public function getByEmail(string $email): ?User
|
|
{
|
|
$select = new Select(\Container::$dbConnection);
|
|
$select->where('email', '=', $email);
|
|
|
|
return $this->pdm->selectFromDb($select, User::class);
|
|
}
|
|
|
|
public function getByUsername(string $username): ?User
|
|
{
|
|
$select = new Select(\Container::$dbConnection);
|
|
$select->where('username', '=', $username);
|
|
|
|
return $this->pdm->selectFromDb($select, User::class);
|
|
}
|
|
|
|
public function getByEmailOrUsername(string $emailOrUsername): ?User
|
|
{
|
|
if (filter_var($emailOrUsername, FILTER_VALIDATE_EMAIL)) {
|
|
return $this->getByEmail($emailOrUsername);
|
|
}
|
|
|
|
return $this->getByUsername($emailOrUsername);
|
|
}
|
|
|
|
public function getByGoogleSub(string $sub): ?User
|
|
{
|
|
$select = new Select(\Container::$dbConnection);
|
|
$select->where('google_sub', '=', $sub);
|
|
|
|
return $this->pdm->selectFromDb($select, User::class);
|
|
}
|
|
}
|