Account.php in Service Container 7.2
File
src/Session/Account.php
View source
<?php
namespace Drupal\service_container\Session;
use Drupal\Core\Session\AccountInterface;
use Drupal\service_container\Legacy\Drupal7;
use Drupal\service_container\Variable;
class Account implements AccountInterface {
protected $drupal7;
protected $variable;
public function __construct(Drupal7 $drupal7, Variable $variable) {
$this->drupal7 = $drupal7;
$this->variable = $variable;
}
public function id() {
return $GLOBALS['user']->uid;
}
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;
}
public function hasPermission($permission) {
return $this->drupal7
->user_access($permission, $GLOBALS['user']);
}
public function getSessionId() {
throw new \BadMethodCallException(sprintf('%s is not implemented', __FUNCTION__));
}
public function getSecureSessionId() {
throw new \BadMethodCallException(sprintf('%s is not implemented', __FUNCTION__));
}
public function getSessionData() {
return $_SESSION;
}
public function isAuthenticated() {
return $this->drupal7
->user_is_logged_in();
}
public function isAnonymous() {
return $this->drupal7
->user_is_anonymous();
}
public function getPreferredLangcode($fallback_to_default = TRUE) {
throw new \BadMethodCallException(sprintf('%s is not implemented', __FUNCTION__));
}
public function getPreferredAdminLangcode($fallback_to_default = TRUE) {
throw new \BadMethodCallException(sprintf('%s is not implemented', __FUNCTION__));
}
public function getUsername() {
return $GLOBALS['user']->name;
}
public function getEmail() {
return $GLOBALS['user']->mail;
}
public function getTimeZone() {
return $this->drupal7
->drupal_get_user_timezone();
}
public function getLastAccessedTime() {
return $GLOBALS['user']->access;
}
public function getHostname() {
return $GLOBALS['user']->hostname;
}
}
Classes
Name |
Description |
Account |
Wraps the global user to provide the account interface. |