PermissionsHashGenerator::generate

public PermissionsHashGenerator::generate(AccountInterface $account)

Cached by role, invalidated whenever permissions change.

Overrides PermissionsHashGeneratorInterface::generate

File

core/lib/Drupal/Core/Session/PermissionsHashGenerator.php, line 57

Class

PermissionsHashGenerator
Generates and caches the permissions hash for a user.

Namespace

Drupal\Core\Session

Code

public function generate(AccountInterface $account) {
  // User 1 is the super user, and can always access all permissions. Use a
  // different, unique identifier for the hash.
  if ($account->id() == 1) {
    return $this->hash('is-super-user');
  }

  $sorted_roles = $account->getRoles();
  sort($sorted_roles);
  $role_list = implode(',', $sorted_roles);
  $cid = "user_permissions_hash:$role_list";
  if ($static_cache = $this->static->get($cid)) {
    return $static_cache->data;
  }
  else {
    $tags = Cache::buildTags('config:user.role', $sorted_roles, '.');
    if ($cache = $this->cache->get($cid)) {
      $permissions_hash = $cache->data;
    }
    else {
      $permissions_hash = $this->doGenerate($sorted_roles);
      $this->cache->set($cid, $permissions_hash, Cache::PERMANENT, $tags);
    }
    $this->static->set($cid, $permissions_hash, Cache::PERMANENT, $tags);
  }

  return $permissions_hash;
}
doc_Drupal
2016-10-29 09:33:43
Comments
Leave a Comment

Please login to continue.