@param int $maxLocks    The maximum number of locks that can be acquired from the semaphore.
@param int $permissions Permissions to access the semaphore.

@throws SemaphoreException If the semaphore could not be created due to an internal error.
194915
private function init($maxLocks, $permissions)
    {
        $maxLocks = (int) $maxLocks;
        if ($maxLocks < 1) {
            $maxLocks = 1;
        }

        $this->key = abs(crc32(spl_object_hash($this)));
        $this->maxLocks = $maxLocks;

        $this->queue = msg_get_queue($this->key, $permissions);
        if (!$this->queue) {
            throw new SemaphoreException('Failed to create the semaphore.');
        }

        // Fill the semaphore with locks.
        while (--$maxLocks >= 0) {
            $this->release();
        }
    }
306120
protected function setDirPermissions($permissions)
    {
        $permissions = (int) $permissions;

        if (! (0b100000000 & $permissions)) {
            throw new InvalidArgumentException(sprintf(
                'Invalid permissions "%s" for directories. '
                . 'Directories will not available for reading.',
                decoct($permissions)
            ));
        }
        if (! (0b010000000 & $permissions)) {
            throw new InvalidArgumentException(sprintf(
                'Invalid permissions "%s" for directories. '
                . 'Directories will not available for writing.',
                decoct($permissions)
            ));
        }
        if (! (0b001000000 & $permissions)) {
            throw new InvalidArgumentException(sprintf(
                'Invalid permissions "%s" for directories. '
                . 'The content of directories will not available.',
                decoct($permissions)
            ));
        }
        $this->dirPermissions = $permissions;
    }
897314
public function syncPermissions($permissions)
    {
        $sync = [];
        $this->mapArray($permissions, function ($permission) use (&$sync) {

            $sync[] = $this->parsePermissionId($permission);

            return $sync;
        });

        return $this->permissions()->sync($sync);
    }
1024514
public function grantPermissions($permissions): void
    {
        if (!is_array($permissions) && !$permissions instanceof Collection) {
            $permissions = func_get_args();
        }

        foreach ($permissions as $permission) {
            $permission = $this->resolvePermission($permission);

            $permission->assignTo($this);
        }
    }
112955
protected function checkPermissions(array $permissions, $reset = FALSE) {

    if (!isset($this->availablePermissons) || $reset) {
      $this->availablePermissons = array_keys(module_invoke_all('permission'));
    }

    $valid = TRUE;
    foreach ($permissions as $permission) {
      if (!in_array($permission, $this->availablePermissons)) {
        $valid = FALSE;
      }
    }
    return $valid;
  }
767386
public function addPermissions($permissions) {
		foreach ($permissions as $permission) {
			$per                                 = new permission($permission);
			$this->role->sharedPermissionList [] = $per->get();
		}
		R::store($this->role);
	}
666208
public function setPermissionsAttribute($permissions)
    {
        $module = lcfirst($this->attributes['name']);

        $roles = array();

        //prefix the permission with the module name ex: user.create
        foreach ($permissions as $key => $value)
        {
            $roles[] = $module . '.' . $value;
        }

        $this->attributes['permissions'] = ( ! empty($roles)) ? json_encode($roles) : '';
    }
104223
private function init(int $locks)
    {
        $locks = (int) $locks;
        if ($locks < 1) {
            $locks = 1;
        }

        $this->semaphore = new Internal\Semaphore($locks);
        $this->maxLocks = $locks;
    }
644001
private function cumulatePermissions(array $userPermission, array $permissions)
    {
        return $this->mapPermissions($userPermission, $permissions, function($permission1, $permission2) {
            return $permission1 || $permission2;
        });
    }
981436
protected function getBypassedAccess($permissions, array $context): bool
    {
        $newPermissions = [false];
        if (is_array($permissions) && array_key_exists('NO_BYPASS', $permissions)) {
            $newPermissions['NO_BYPASS'] = $permissions['NO_BYPASS'];
        }

        try {
            return $this->lpProxy->checkAccess($newPermissions, $context);
        } catch (\Exception $e) {
        }

        return false;
    }
903827
public function grant($permissions, $resourceName = null, $resourceId = null)
    {
        return $this->lock()->allow($permissions, $resourceName, $resourceId);
    }
1139318
public function hasAnyPermission(...$permissions): bool
    {
        if (is_array($permissions[0])) {
            $permissions = $permissions[0];
        }

        foreach ($permissions as $permission) {
            if ($this->checkPermissionTo($permission)) {
                return true;
            }
        }

        return false;
    }
952061
public function hookUserRolePermissions(array &$permissions)
    {
        $permissions['module_file_manager'] = gplcart_text('File manager: access');

        foreach ($this->getHandlers() as $command_id => $command) {
            $permissions["module_file_manager_$command_id"] = gplcart_text('File manager: perform command @name', array(
                '@name' => $command['name']));
        }
    }
657915
private function lock($name = null, $blocking = false)
    {
        if (!class_exists(SemaphoreStore::class)) {
            throw new LogicException('To enable the locking feature you must install the symfony/lock component.');
        }

        if (null !== $this->lock) {
            throw new LogicException('A lock is already in place.');
        }

        if (SemaphoreStore::isSupported()) {
            $store = new SemaphoreStore();
        } else {
            $store = new FlockStore();
        }

        $this->lock = (new Factory($store))->createLock($name ?: $this->getName());
        if (!$this->lock->acquire($blocking)) {
            $this->lock = null;

            return false;
        }

        return true;
    }
1222815
public function setPermissions($permissions)
	{
		if (is_string($permissions))
		{
			$permissions = '0'.ltrim($permissions, '0');
			$permissions = octdec($permissions);
		}

		return chmod($this->path, $permissions);
	}
1194620
public static function CompilePermissions($Permissions) {
      $Compiled = array();
      foreach ($Permissions as $i => $Row) {
         $JunctionID = array_key_exists('JunctionID', $Row) ? $Row['JunctionID'] : null;
         //$JunctionTable = array_key_exists('JunctionColumn', $Row) ? $Row['JunctionTable'] : null;
         //$JunctionColumn = array_key_exists('JunctionColumn', $Row) ? $Row['JunctionColumn'] : null;
         unset($Row['JunctionColumn'], $Row['JunctionColumn'], $Row['JunctionID'], $Row['RoleID'], $Row['PermissionID']);
         
         foreach ($Row as $PermissionName => $Value) {
            if ($Value == 0)
               continue;
            
            if (is_numeric($JunctionID) && $JunctionID !== NULL) {
               if (!array_key_exists($PermissionName, $Compiled))
                  $Compiled[$PermissionName] = array();
                  
               if (!is_array($Compiled[$PermissionName]))
                  $Compiled[$PermissionName] = array();
                  
               $Compiled[$PermissionName][] = $JunctionID;
            } else {
               $Compiled[] = $PermissionName;
            }
         }
      }
      
      return $Compiled;
   }
707848
public function setPermissionsAttribute($permissions)
    {
        if (! ($permissions instanceof ChannelPermission)) {
            return;
        }

        list($allow, $deny) = $permissions->bitwise;
        $this->allow        = $allow;
        $this->deny         = $deny;

        $this->attributes['permissions'] = $permissions;
    }