federator/php/dio/user.php

61 lines
1.7 KiB
PHP
Raw Normal View History

2024-07-15 20:46:44 +02:00
<?php
/**
* SPDX-FileCopyrightText: 2024 Sascha Nitsch (grumpydeveloper) https://contentnation.net/@grumpydevelop
* SPDX-License-Identifier: GPL-3.0-or-later
*
* @author Sascha Nitsch (grumpydeveloper)
**/
namespace Federator\DIO;
/**
* IO functions related to users
*/
class User
{
/**
* extend the given user with internal data
* @param \mysqli $dbh database handle @unused-param
* @param \Federator\Data\User $user user to extend @unused-param
*/
protected static function extendUser(\mysqli $dbh, \Federator\Data\User $user) : void
{
// do nothing for now
// TODO: if a new user, create own database entry with additionally needed info
}
/**
* get User by session id
*
* @param \mysqli $dbh
* database handle
* @param string $_session
* session
* @param string $_user
* user/profile name
* @param \Connector\Connector? $connector @unused-param
* connector to fetch use with
* @param \Cache\Cache? $cache
* optional caching service
* @return \Data\User|bool
*/
public static function getUserBySession($dbh, $_session, $_user, $connector, $cache)
{
$user = false;
if ($cache) {
$user = $cache->getRemoteUserBySession($_session, $_user);
}
// ask connector for user-id
$user = $connector->getRemoteUserBySession($_session, $_user);
if ($user === false) {
return false;
}
if ($cache) {
$cache->saveRemoteUserBySession($_session, $_user, $user);
}
self::extendUser($dbh, $user);
return $user;
}
}