class CalculatedPermissionsItem

Same name in other branches
  1. 11.x core/lib/Drupal/Core/Session/CalculatedPermissionsItem.php \Drupal\Core\Session\CalculatedPermissionsItem

Represents a single entry for the calculated permissions.

Hierarchy

Expanded class hierarchy of CalculatedPermissionsItem

See also

\Drupal\Core\Session\ChainPermissionCalculator

9 files declare their use of CalculatedPermissionsItem
AccessPolicyProcessorTest.php in core/tests/Drupal/Tests/Core/Session/AccessPolicyProcessorTest.php
CalculatedPermissionsItemTest.php in core/tests/Drupal/Tests/Core/Session/CalculatedPermissionsItemTest.php
CalculatedPermissionsTest.php in core/tests/Drupal/Tests/Core/Session/CalculatedPermissionsTest.php
InstallerAccessPolicy.php in core/lib/Drupal/Core/Installer/InstallerAccessPolicy.php
PermissionCheckerTest.php in core/tests/Drupal/Tests/Core/Session/PermissionCheckerTest.php

... See full list

File

core/lib/Drupal/Core/Session/CalculatedPermissionsItem.php, line 10

Namespace

Drupal\Core\Session
View source
class CalculatedPermissionsItem implements CalculatedPermissionsItemInterface {
    
    /**
     * Constructs a new CalculatedPermissionsItem.
     *
     * @param string[] $permissions
     *   The permission names.
     * @param bool $isAdmin
     *   (optional) Whether the item grants admin privileges.
     * @param string $scope
     *   (optional) The scope name, defaults to 'drupal'.
     * @param string|int $identifier
     *   (optional) The identifier within the scope, defaults to 'drupal'.
     */
    public function __construct(array $permissions, bool $isAdmin = FALSE, string $scope = AccessPolicyInterface::SCOPE_DRUPAL, string|int $identifier = AccessPolicyInterface::SCOPE_DRUPAL) {
        $this->permissions = $isAdmin ? [] : array_unique($permissions);
    }
    
    /**
     * {@inheritdoc}
     */
    public function getScope() : string {
        return $this->scope;
    }
    
    /**
     * {@inheritdoc}
     */
    public function getIdentifier() : string|int {
        return $this->identifier;
    }
    
    /**
     * {@inheritdoc}
     */
    public function getPermissions() : array {
        return $this->permissions;
    }
    
    /**
     * {@inheritdoc}
     */
    public function isAdmin() : bool {
        return $this->isAdmin;
    }
    
    /**
     * {@inheritdoc}
     */
    public function hasPermission(string $permission) : bool {
        return $this->isAdmin() || in_array($permission, $this->permissions, TRUE);
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
CalculatedPermissionsItem::getIdentifier public function Returns the identifier within the scope. Overrides CalculatedPermissionsItemInterface::getIdentifier
CalculatedPermissionsItem::getPermissions public function Returns the permissions for the calculated permissions item. Overrides CalculatedPermissionsItemInterface::getPermissions
CalculatedPermissionsItem::getScope public function Returns the scope of the calculated permissions item. Overrides CalculatedPermissionsItemInterface::getScope
CalculatedPermissionsItem::hasPermission public function Returns whether this item has a given permission. Overrides CalculatedPermissionsItemInterface::hasPermission
CalculatedPermissionsItem::isAdmin public function Returns whether this item grants admin privileges in its scope. Overrides CalculatedPermissionsItemInterface::isAdmin
CalculatedPermissionsItem::__construct public function Constructs a new CalculatedPermissionsItem.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.