class PermissionChecker

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

Checks permissions for an account.

Hierarchy

Expanded class hierarchy of PermissionChecker

1 file declares its use of PermissionChecker
PermissionCheckerTest.php in core/tests/Drupal/Tests/Core/Session/PermissionCheckerTest.php
1 string reference to 'PermissionChecker'
core.services.yml in core/core.services.yml
core/core.services.yml
1 service uses PermissionChecker
permission_checker in core/core.services.yml
Drupal\Core\Session\PermissionChecker

File

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

Namespace

Drupal\Core\Session
View source
class PermissionChecker implements PermissionCheckerInterface {
  public function __construct(protected EntityTypeManagerInterface|AccessPolicyProcessorInterface $processor) {
    if ($this->processor instanceof EntityTypeManagerInterface) {
      @trigger_error('Calling ' . __METHOD__ . '() without the $processor argument is deprecated in drupal:10.3.0 and will be required in drupal:11.0.0. See https://www.drupal.org/node/3402107', E_USER_DEPRECATED);
      $this->processor = \Drupal::service('access_policy_processor');
    }
  }
  
  /**
   * {@inheritdoc}
   */
  public function hasPermission(string $permission, AccountInterface $account) : bool {
    $item = $this->processor
      ->processAccessPolicies($account)
      ->getItem();
    return $item && $item->hasPermission($permission);
  }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
PermissionChecker::hasPermission public function Checks whether an account has a permission. Overrides PermissionCheckerInterface::hasPermission
PermissionChecker::__construct public function

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