User.php 693 B

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