"Fossies" - the Fresh Open Source Software Archive

Member "drupal-8.9.10/core/modules/user/src/Access/PermissionAccessCheck.php" (26 Nov 2020, 1242 Bytes) of package /linux/www/drupal-8.9.10.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "PermissionAccessCheck.php" see the Fossies "Dox" file reference documentation.

    1 <?php
    2 
    3 namespace Drupal\user\Access;
    4 
    5 use Drupal\Core\Access\AccessResult;
    6 use Drupal\Core\Routing\Access\AccessInterface;
    7 use Drupal\Core\Session\AccountInterface;
    8 use Symfony\Component\Routing\Route;
    9 
   10 /**
   11  * Determines access to routes based on permissions defined via
   12  * $module.permissions.yml files.
   13  */
   14 class PermissionAccessCheck implements AccessInterface {
   15 
   16   /**
   17    * Checks access.
   18    *
   19    * @param \Symfony\Component\Routing\Route $route
   20    *   The route to check against.
   21    * @param \Drupal\Core\Session\AccountInterface $account
   22    *   The currently logged in account.
   23    *
   24    * @return \Drupal\Core\Access\AccessResultInterface
   25    *   The access result.
   26    */
   27   public function access(Route $route, AccountInterface $account) {
   28     $permission = $route->getRequirement('_permission');
   29 
   30     if ($permission === NULL) {
   31       return AccessResult::neutral();
   32     }
   33 
   34     // Allow to conjunct the permissions with OR ('+') or AND (',').
   35     $split = explode(',', $permission);
   36     if (count($split) > 1) {
   37       return AccessResult::allowedIfHasPermissions($account, $split, 'AND');
   38     }
   39     else {
   40       $split = explode('+', $permission);
   41       return AccessResult::allowedIfHasPermissions($account, $split, 'OR');
   42     }
   43   }
   44 
   45 }