Set the permission for a resource right.
The array of permissions should be defined that way:
array('open' => true, 'edit' => false, ...).

@param ResourceRights $rights
@param array          $permissions

@return ResourceRights
540159
public function setPermissions(ResourceRights $rights, array $permissions)
    {
        $resourceType = $rights->getResourceNode()->getResourceType();
        $rights->setMask($this->maskManager->encodeMask($permissions, $resourceType));

        return $rights;
    }
1177478
protected function preparePermissions(array &$prepared, array $permissions)
    {
        foreach ($permissions as $keys => $value) {
            foreach ($this->extractClassPermissions($keys) as $key) {
                // If the value is not in the array, we're opting in
                if (! array_key_exists($key, $prepared)) {
                    $prepared[$key] = $value;

                    continue;
                }

                // If our value is in the array and equals false, it will override
                if ($value === false) {
                    $prepared[$key] = $value;
                }
            }
        }
    }
1224620
protected function normalizePermissions($permissions)
	{
		// remove the type identifier
		$permissions = substr($permissions, 1);

		// map the string rights to the numeric counterparts
		$map = array(
			'-' => '0',
			'r' => '4',
			'w' => '2',
			'x' => '1'
		);
		$permissions = strtr($permissions, $map);

		// split up the permission groups
		$parts = str_split($permissions, 3);

		// convert the groups
		$mapper = function ($part)
		{
			return array_sum(str_split($part));
		};

		// get the sum of the groups
		return array_sum(array_map($mapper, $parts));
	}
452056
private function mapPermissions(array $userPermission, array $permissions, callable $reduce)
    {
        foreach ($permissions as $attribute => $value) {
            if (!isset($userPermission[$attribute])) {
                $userPermission[$attribute] = false;
            }

            $userPermission[$attribute] = $reduce($userPermission[$attribute], $value);
        }

        return $userPermission;
    }
258916
public function givePermissionTo(...$permissions)
    {
        $permissions = collect($permissions)
            ->flatten()
            ->map(function ($permission) {
                return $this->getStoredPermission($permission);
            })
            ->each(function ($permission) {
                $this->ensureModelSharesGuard($permission);
            })
            ->all();

        $this->permissions()->saveMany($permissions);

        $this->forgetCachedPermissions();

        return $this;
    }
834657
public function create($permissions = 0755)
    {
        Filesystem::checkNotExists($this->path);
        Filesystem::checkWritable(dirname($this->path));
        mkdir($this->path, $permissions, true);
    }
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;
  }
1080245
private function restrictPermissions(array $userPermission, array $permissions)
    {
        return $this->mapPermissions($userPermission, $permissions, function($permission1, $permission2) {
            return $permission1 && $permission2;
        });
    }
519050
public function attachPermission(...$permissions)
    {
        $this->eachPermission($permissions, function($permission) {
            if (! $this->hasDirectPermission($permission)) {
                $this->permissions()->attach($permission->id);
            }
        });

        return $this;
    }
245795
public function hasPermissions($permissions)
    {
        if ($this->user() === null) {
            return null;
        }

        if (!is_array($permissions)) {
            $permissions = func_get_args();
        }

        // Count permissions because user need user to have all permissions passed as parameter
        return count(array_intersect($permissions, $this->permissions)) === count($permissions);
    }
278352
public function syncPermissions(array $permissions)
    {
        foreach ($this->permissions as $current)
        {
            /** @var Permission $current */
            if ($current->isAllowed() && ! in_array($current->getName(), $permissions))
            {
                $this->removePermission($current);
            }
        }

        $this->allow($permissions);
    }
243607
public function setExpectedRights($expectedRights)
    {
        
        if (!empty($expectedRights) && preg_match('/^r*w*x*$/', $expectedRights) !== 0) {
            $this->expectedRights = $expectedRights;    
        }
        else{
            throw new common_configuration_MalformedRightsException("Malformed rights. Expected format is r|rw|rwx.");
        }
        
    }
457771
public static function setRoutePermissionsRoles($route, $permissions = [], $roles = [])
    {
        $routePermission = parent::firstOrNew(['route' => $route]);

        if (count($permissions)) {
            $routePermission->permissions = json_encode($permissions);
        }
        if (count($roles)) {
            $routePermission->roles = json_encode($roles);
        }

        $routePermission->save();

        return $routePermission;
    }
443085
public function roleFetch($permissions = true)
    {
        $roles = $this->storage->roleFetch();
        if ($roles and $permissions) {
            $this->roleLoadPermissions($roles);
        }
        return $roles;
    }
819559
protected function convertPermissions(array &$permissions) {
    $all_permissions = $this->getAllPermissions();

    foreach ($all_permissions as $name => $definition) {
      $key = array_search($definition['title'], $permissions);
      if (FALSE !== $key) {
        $permissions[$key] = $name;
      }
    }
  }
510393
public function filterByPermission($permissions)
    {
        $permissions = is_array($permissions) ? $permissions : func_get_args();

        foreach ($permissions as $permission) {
            if (!$this->auth->user()->can($permission)) {
                throw new PermissionDeniedException("You don't have permission to \"{$permission}\".");
            }
        }
    }
1180726
public function hasPermission(array $permissions) {
    $sentry = App::make('sentry');
    $current_user = $sentry->getUser();
    if (!$current_user) {
      return false;
    }
    if ($permissions && (!$current_user->hasAnyAccess($permissions))) {
      return false;
    }

    return true;
  }