Mutator for taking permissions.

@param  array  $permissions
@return void
@throws \InvalidArgumentException
425877
public function setPermissionsAttribute(array $permissions)
	{
		// Merge permissions
		$permissions = array_merge($this->getPermissions(), $permissions);

		// Loop through and adjust permissions as needed
		foreach ($permissions as $permission => &$value)
		{
			// Lets make sure their is a valid permission value
			if ( ! in_array($value = (int) $value, $this->allowedPermissionsValues))
			{
				throw new \InvalidArgumentException("Invalid value [$value] for permission [$permission] given.");
			}

			// If the value is 0, delete it
			if ($value === 0)
			{
				unset($permissions[$permission]);
			}
		}

		$this->attributes['permissions'] = ( ! empty($permissions)) ? $permissions : '';
	}
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) : '';
    }
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;
                }
            }
        }
    }
50072
public function detachPermission(...$permissions)
    {
        $this->eachPermission($permissions, function($permission) {
            if ($this->hasDirectPermission($permission)) {
                $this->permissions()->detach($permission->id);
            }
        });

        return $this;
    }
318705
public function setPermissionsAttribute(array $permissions = [])
    {
        foreach ($permissions as $key => $value) {
            $permissions[$key] = (bool) $value;
        }
        $this->attributes['permissions'] = json_encode($permissions ?? []);
    }
516358
public static function createFromData($permissions)
    {
        return array_map(function ($permission) {
            if (is_array($permission)) {
                return PermissionFactory::createFromArray($permission);
            } else {
                return PermissionFactory::createFromObject($permission);
            }
        }, $permissions);
    }
18772
public static function formatPermissions(array $userPermissions): array
    {
        $userPermissions = self::format($userPermissions);

        foreach ($userPermissions as $key => $permission) {
            $userPermissions[$key] = self::$permissions[$key];
        }

        return $userPermissions;
    }
125669
public static function createAskForPermissionsConsent(array $permissions): self
    {
        if (empty($permissions) || !empty(array_diff($permissions, self::PERMISSIONS))) {
            throw new InvalidCardPermissionsException();
        }

        $card = new self(self::TYPE_ASK_FOR_PERMISSIONS_CONSENT);

        $card->permissions = $permissions;

        return $card;
    }
1165193
public function addCollection(PermissionCollection $permissions)
    {
        if ($permissions->getObjectType() !== $this->getObjectType()) {
            throw new InvalidArgumentException('Mismating object types.');
        }

        foreach ($permissions->all() as $permission) {
            $this->add($permission);
        }

        return $this;
    }
618231
protected function convertToPermissionModels($permissions): array
    {
        if ($permissions instanceof Collection) {
            $permissions = $permissions->all();
        }

        $permissions = array_wrap($permissions);

        return array_map(function ($permission) {
            if ($permission instanceof Permission) {
                return $permission;
            }

            return app(Permission::class)->findByName($permission, $this->getDefaultGuardName());
        }, $permissions);
    }
870263
protected function setPermissions($permissions)
    {
        foreach ($permissions as $action => $permission) {
            $this->setPermission($action, $permission);
        }
    }
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;
    }
1341081
protected function addPermissions(Collection $permissions)
    {
        foreach ($permissions as $permission) {
            $this->permissions[] = $permission->token;
        }
    }
734083
public function flattenPermissions($permissions)
    {
        $flattened = array();
        foreach ($permissions as $itemName => $itemPermissions) {
            $flattened[$itemName] = $itemPermissions;

            if (isset($itemPermissions['children'])) {
                $children = $itemPermissions['children'];
                unset($itemPermissions['children']); // not needed in a flat tree
                $flattened = array_merge($flattened, $this->flattenPermissions($children));
            }

            if (isset($itemPermissions['parents'])) {
                $parents = $itemPermissions['parents'];
                unset($itemPermissions['parents']);
                $flattened = array_merge($flattened, $this->flattenPermissions($parents));
            }
        }
        return $flattened;
    }
317980
public function resolve(PermissionCollection $permissions, $mask)
    {
        $resolvedPermissions = array();

        foreach ($permissions->all() as $permission) {
            if ($permission->getBit() & $mask) {
                $resolvedPermissions[] = $permission;
                $mask = $mask ^ $permission->getBit();
            }
        }

        if ($mask) {
            $bits = decbin($mask);
            throw new InvalidArgumentException("Permission for bits $bits not found.");
        }

        return $resolvedPermissions;
    }
469379
public function createRepositoryPermissions($permissions)
    {
		$url = $this->service_url . '/permissions';
		$body = json_encode(array('permission' => $permissions));
		$permissions = $this->service->prepAndSend($url, array(201), 'POST', $body, true, 'application/collection+json', 'application/json');
        return self::batchDataToArray($permissions);
	}
92608
private function extractPermissions(array $userPermissions = array())
    {
        $permissions = array(
            'configure' => '',
            'read' => '',
            'write' => '',
        );

        if (!empty($userPermissions)) {
            foreach (array_keys($permissions) as $permission) {
                if (!empty($userPermissions[$permission])) {
                    $permissions[$permission] = $userPermissions[$permission];
                }
            }
        }

        return $permissions;
    }