You are here

class Account in Service Container 7

Same name and namespace in other branches
  1. 7.2 src/Session/Account.php \Drupal\service_container\Session\Account

Wraps the global user to provide the account interface.

@codeCoverageIgnore

Hierarchy

Expanded class hierarchy of Account

1 file declares its use of Account
CurrentUserIntegrationTest.php in lib/Drupal/service_container/Tests/CurrentUserIntegrationTest.php
Contains \Drupal\service_container\Tests\CurrentUserIntegrationTest.

File

src/Session/Account.php, line 19
Contains \Drupal\service_container\Session\Account.

Namespace

Drupal\service_container\Session
View source
class Account implements AccountInterface {

  /**
   * The Drupal7 service.
   *
   * @var \Drupal\service_container\Legacy\Drupal7
   */
  protected $drupal7;

  /**
   * The variable storage.
   *
   * @var \Drupal\service_container\Variable
   */
  protected $variable;

  /**
   * Constructs a new Account instance.
   *
   * @param \Drupal\service_container\Legacy\Drupal7 $drupal7
   *   The Drupal7 service.
   * @param \Drupal\service_container\Variable $variable
   *   The variable storage.
   */
  public function __construct(Drupal7 $drupal7, Variable $variable) {
    $this->drupal7 = $drupal7;
    $this->variable = $variable;
  }

  /**
   * {@inheritdoc}
   */
  public function id() {
    return $GLOBALS['user']->uid;
  }

  /**
   * {@inheritdoc}
   */
  public function getRoles($exclude_locked_roles = FALSE) {
    $rids = array_keys($GLOBALS['user']->roles);
    if ($exclude_locked_roles) {
      $rids = array_filter($rids, function ($value) {
        return $value != DRUPAL_ANONYMOUS_RID && $value != DRUPAL_AUTHENTICATED_RID;
      });
    }
    return $rids;
  }

  /**
   * {@inheritdoc}
   */
  public function hasPermission($permission) {
    return $this->drupal7
      ->user_access($permission, $GLOBALS['user']);
  }

  /**
   * {@inheritdoc}
   */
  public function getSessionId() {
    throw new \BadMethodCallException(sprintf('%s is not implemented', __FUNCTION__));
  }

  /**
   * {@inheritdoc}
   */
  public function getSecureSessionId() {
    throw new \BadMethodCallException(sprintf('%s is not implemented', __FUNCTION__));
  }

  /**
   * {@inheritdoc}
   */
  public function getSessionData() {
    return $_SESSION;
  }

  /**
   * {@inheritdoc}
   */
  public function isAuthenticated() {
    return $this->drupal7
      ->user_is_logged_in();
  }

  /**
   * {@inheritdoc}
   */
  public function isAnonymous() {
    return $this->drupal7
      ->user_is_anonymous();
  }

  /**
   * {@inheritdoc}
   */
  public function getPreferredLangcode($fallback_to_default = TRUE) {
    throw new \BadMethodCallException(sprintf('%s is not implemented', __FUNCTION__));
  }

  /**
   * {@inheritdoc}
   */
  public function getPreferredAdminLangcode($fallback_to_default = TRUE) {
    throw new \BadMethodCallException(sprintf('%s is not implemented', __FUNCTION__));
  }

  /**
   * {@inheritdoc}
   */
  public function getUsername() {
    return $GLOBALS['user']->name;
  }

  /**
   * {@inheritdoc}
   */
  public function getEmail() {
    return $GLOBALS['user']->mail;
  }

  /**
   * {@inheritdoc}
   */
  public function getTimeZone() {
    return $this->drupal7
      ->drupal_get_user_timezone();
  }

  /**
   * {@inheritdoc}
   */
  public function getLastAccessedTime() {
    return $GLOBALS['user']->access;
  }

  /**
   * {@inheritdoc}
   */
  public function getHostname() {
    return $GLOBALS['user']->hostname;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Account::$drupal7 protected property The Drupal7 service.
Account::$variable protected property The variable storage.
Account::getEmail public function Returns the email address of this account. Overrides AccountInterface::getEmail
Account::getHostname public function
Account::getLastAccessedTime public function The timestamp when the account last accessed the site. Overrides AccountInterface::getLastAccessedTime
Account::getPreferredAdminLangcode public function Returns the preferred administrative language code of the account. Overrides AccountInterface::getPreferredAdminLangcode
Account::getPreferredLangcode public function Returns the preferred language code of the account. Overrides AccountInterface::getPreferredLangcode
Account::getRoles public function Returns a list of roles. Overrides AccountInterface::getRoles
Account::getSecureSessionId public function
Account::getSessionData public function
Account::getSessionId public function
Account::getTimeZone public function Returns the timezone of this account. Overrides AccountInterface::getTimeZone
Account::getUsername public function Returns the username of this account. Overrides AccountInterface::getUsername
Account::hasPermission public function Checks whether a user has a certain permission. Overrides AccountInterface::hasPermission
Account::id public function Returns the user ID or 0 for anonymous. Overrides AccountInterface::id
Account::isAnonymous public function Returns TRUE if the account is anonymous. Overrides AccountInterface::isAnonymous
Account::isAuthenticated public function Returns TRUE if the account is authenticated. Overrides AccountInterface::isAuthenticated
Account::__construct public function Constructs a new Account instance.
AccountInterface::ANONYMOUS_ROLE constant Role ID for anonymous users.
AccountInterface::AUTHENTICATED_ROLE constant Role ID for authenticated users.