class UserSession

An implementation of the user account interface for the global user.

@todo: Change all properties to protected.

Hierarchy

Expanded class hierarchy of UserSession

2 files declare their use of UserSession
bootstrap.inc in drupal/core/includes/bootstrap.inc
Functions that need to be loaded on every Drupal request.
session.inc in drupal/core/includes/session.inc
User session handling functions.

File

drupal/core/lib/Drupal/Core/Session/UserSession.php, line 15
Contains \Drupal\Core\Session\UserSession.

Namespace

Drupal\Core\Session
View source
class UserSession implements AccountInterface {

  /**
   * User ID.
   *
   * @var int
   */
  public $uid;

  /**
   * Session hostname.
   *
   * @todo: This does not seem to be used, remove?
   *
   * @var string
   */
  public $hostname;

  /**
   * List of the roles this user has.
   *
   * @var array
   */
  public $roles;

  /**
   * Session ID.
   *
   * @var string.
   */
  public $sid;

  /**
   * Secure session ID.
   *
   * @var string.
   */
  public $ssid;

  /**
   * Session data.
   *
   * @var array.
   */
  public $session;

  /**
   * The Unix timestamp when this session last requested a page.
   *
   * @var string.
   */
  public $timestamp;

  /**
   * Constructs a new user session.
   *
   * @param array $values
   *   Array of initial values for the user sesion.
   */
  public function __construct(array $values = array()) {
    foreach ($values as $key => $value) {
      $this->{$key} = $value;
    }
  }

  /**
   * {@inheritdoc}
   */
  public function id() {
    return $this->uid;
  }

  /**
   * {@inheritdoc}
   */
  public function getRoles() {
    return $this->roles;
  }

  /**
   * {@inheritdoc}
   */
  public function getSecureSessionId() {
    return $this->ssid;
  }

  /**
   * {@inheritdoc}
   */
  public function getSessionData() {
    return $this->session;
  }

  /**
   * {@inheritdoc}
   */
  public function getSessionId() {
    return $this->sid;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
UserSession::$hostname public property Session hostname.
UserSession::$roles public property List of the roles this user has.
UserSession::$session public property Session data.
UserSession::$sid public property Session ID.
UserSession::$ssid public property Secure session ID.
UserSession::$timestamp public property The Unix timestamp when this session last requested a page.
UserSession::$uid public property User ID.
UserSession::getRoles public function Returns a list of roles. Overrides AccountInterface::getRoles
UserSession::getSecureSessionId public function Returns the secure session ID. Overrides AccountInterface::getSecureSessionId
UserSession::getSessionData public function Returns the session data. Overrides AccountInterface::getSessionData
UserSession::getSessionId public function Returns the session ID. Overrides AccountInterface::getSessionId
UserSession::id public function Returns the user ID or 0 for anonymous. Overrides AccountInterface::id
UserSession::__construct public function Constructs a new user session.