User.php 720 B

12345678910111213141516171819202122232425262728
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * The Minz_User class handles the user information.
  5. */
  6. final class Minz_User {
  7. public const INTERNAL_USER = '_';
  8. public const CURRENT_USER = 'currentUser';
  9. /**
  10. * @return string the name of the current user, or null if there is none
  11. */
  12. public static function name(): ?string {
  13. $currentUser = trim(Minz_Session::paramString(Minz_User::CURRENT_USER));
  14. return $currentUser === '' ? null : $currentUser;
  15. }
  16. /**
  17. * @param string $name the name of the new user. Set to empty string to clear the user.
  18. */
  19. public static function change(string $name = ''): void {
  20. $name = trim($name);
  21. Minz_Session::_param(Minz_User::CURRENT_USER, $name === '' ? false : $name);
  22. }
  23. }