federator/php/dio/user.php

65 lines
1.8 KiB
PHP

<?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 \Federator\Connector\Connector $connector
* connector to fetch use with
* @param \Federator\Cache\Cache|null $cache
* optional caching service
* @return \Federator\Data\User|false
*/
public static function getUserBySession($dbh, $_session, $_user, $connector, $cache)
{
$saveToCache = false;
$user = false;
if ($cache !== null) {
$user = $cache->getRemoteUserBySession($_session, $_user);
}
if ($user === false) {
// ask connector for user-id
$user = $connector->getRemoteUserBySession($_session, $_user);
$saveToCache = true;
}
if ($user === false) {
return false;
}
self::extendUser($dbh, $user);
if ($cache !== null && $saveToCache) {
$cache->saveRemoteUserBySession($_session, $_user, $user);
}
return $user;
}
}