function AccessPolicyProcessor::processAccessPolicies

Same name and namespace in other branches
  1. 11.x core/lib/Drupal/Core/Session/AccessPolicyProcessor.php \Drupal\Core\Session\AccessPolicyProcessor::processAccessPolicies()
  2. 10 core/lib/Drupal/Core/Session/AccessPolicyProcessor.php \Drupal\Core\Session\AccessPolicyProcessor::processAccessPolicies()

Processes the access policies for an account within a given scope.

Parameters

\Drupal\Core\Session\AccountInterface $account: The user account for which to calculate the permissions.

string $scope: (optional) The scope to calculate the permissions, defaults to 'drupal'.

Return value

\Drupal\Core\Session\CalculatedPermissionsInterface The access policies' permissions within the given scope.

Overrides AccessPolicyProcessorInterface::processAccessPolicies

File

core/lib/Drupal/Core/Session/AccessPolicyProcessor.php, line 42

Class

AccessPolicyProcessor
Processes access policies into permissions for an account.

Namespace

Drupal\Core\Session

Code

public function processAccessPolicies(AccountInterface $account, string $scope = AccessPolicyInterface::SCOPE_DRUPAL) : CalculatedPermissionsInterface {
  // No Fiber isolation is needed when not in a Fiber, or when the requested
  // account is the current user (no account switch will occur in
  // doProcessAccessPolicies, so there is nothing to isolate).
  if (!\Fiber::getCurrent() || $account->id() === $this->currentUser
    ->id()) {
    return $this->doProcessAccessPolicies($account, $scope);
  }
  // If running in a fiber and processing a different account, prevent the
  // account switch from escaping to outside the fiber by resuming the fiber
  // if it was suspended.
  $fiber = new \Fiber([
    $this,
    'doProcessAccessPolicies',
  ]);
  $fiber->start($account, $scope);
  while (!$fiber->isTerminated()) {
    if ($fiber->isSuspended()) {
      $resume_type = $fiber->resume();
      if (!$fiber->isTerminated() && $resume_type !== FiberResumeType::Immediate) {
        usleep(500);
      }
    }
  }
  return $fiber->getReturn();
}

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