aboutsummaryrefslogtreecommitdiff
path: root/lib/Minz/User.php
blob: 8e90a4fb223db1e501f21e4524af0df3234bc208 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<?php
declare(strict_types=1);

/**
 * The Minz_User class handles the user information.
 */
final class Minz_User {

	public const INTERNAL_USER = '_';

	public const CURRENT_USER = 'currentUser';

	/**
	 * @return string the name of the current user, or null if there is none
	 */
	public static function name(): ?string {
		$currentUser = trim(Minz_Session::paramString(Minz_User::CURRENT_USER));
		return $currentUser === '' ? null : $currentUser;
	}

	/**
	 * @param string $name the name of the new user. Set to empty string to clear the user.
	 */
	public static function change(string $name = ''): void {
		$name = trim($name);
		Minz_Session::_param(Minz_User::CURRENT_USER, $name === '' ? false : $name);
	}
}