class Account in Service Container 7.2
Same name and namespace in other branches
- 7 src/Session/Account.php \Drupal\service_container\Session\Account
Wraps the global user to provide the account interface.
@codeCoverageIgnore
Hierarchy
- class \Drupal\service_container\Session\Account implements AccountInterface
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\SessionView 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
| Name   | Modifiers | Type | Description | Overrides | 
|---|---|---|---|---|
| Account:: | protected | property | The Drupal7 service. | |
| Account:: | protected | property | The variable storage. | |
| Account:: | public | function | Returns the email address of this account. Overrides AccountInterface:: | |
| Account:: | public | function | ||
| Account:: | public | function | The timestamp when the account last accessed the site. Overrides AccountInterface:: | |
| Account:: | public | function | Returns the preferred administrative language code of the account. Overrides AccountInterface:: | |
| Account:: | public | function | Returns the preferred language code of the account. Overrides AccountInterface:: | |
| Account:: | public | function | Returns a list of roles. Overrides AccountInterface:: | |
| Account:: | public | function | ||
| Account:: | public | function | ||
| Account:: | public | function | ||
| Account:: | public | function | Returns the timezone of this account. Overrides AccountInterface:: | |
| Account:: | public | function | Returns the username of this account. Overrides AccountInterface:: | |
| Account:: | public | function | Checks whether a user has a certain permission. Overrides AccountInterface:: | |
| Account:: | public | function | Returns the user ID or 0 for anonymous. Overrides AccountInterface:: | |
| Account:: | public | function | Returns TRUE if the account is anonymous. Overrides AccountInterface:: | |
| Account:: | public | function | Returns TRUE if the account is authenticated. Overrides AccountInterface:: | |
| Account:: | public | function | Constructs a new Account instance. | |
| AccountInterface:: | constant | Role ID for anonymous users. | ||
| AccountInterface:: | constant | Role ID for authenticated users. | 
