Return two arrays with the filtered permissions between the permissions
with wildcard and the permissions without it.

@param array $permissions
@return array [$wildcard, $noWildcard]
772642
public static function getPermissionWithAndWithoutWildcards($permissions)
    {
        $wildcard = [];
        $noWildcard = [];

        foreach ($permissions as $permission) {
            if (strpos($permission, '*') === false) {
                $noWildcard[] = $permission;
            } else {
                $wildcard[] = str_replace('*', '%', $permission);
            }
        }

        return [$wildcard, $noWildcard];
    }
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;
    }
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;
    }
1101719
public function givePermissionTo(...$permissions)
    {
        $permissions = collect($permissions)
            ->flatten()
            ->map(function ($permission) {
                if (empty($permission)) {
                    return false;
                }

                return $this->getStoredPermission($permission);
            })
            ->filter(function ($permission) {
                return $permission instanceof Permission;
            })
            ->each(function ($permission) {
                $this->ensureModelSharesGuard($permission);
            })
            ->map->id
            ->all();

        $model = $this->getModel();

        if ($model->exists) {
            $this->permissions()->sync($permissions, false);
            $model->load('permissions');
        } else {
            $class = \get_class($model);

            $class::saved(
                function ($object) use ($permissions, $model) {
                    static $modelLastFiredOn;
                    if ($modelLastFiredOn !== null && $modelLastFiredOn === $model) {
                        return;
                    }
                    $object->permissions()->sync($permissions, false);
                    $object->load('permissions');
                    $modelLastFiredOn = $object;
                }
            );
        }

        $this->forgetCachedPermissions();

        return $this;
    }
871627
protected function getPermissionChecksRecursive($permissions, array $context, array $typeKeys, string $type = null): array {
        if (!is_array($permissions)) {
            $resolvePermissions = $permissions;
            if ($type) {
                $resolvePermissions = [$type => $permissions];
            }

            return [
                [
                    'permissions' => $permissions,
                    'resolve' => $this->lpProxy->checkAccess($resolvePermissions, $context, false),
                ],
            ];
        }

        reset($permissions);
        $key = key($permissions);
        $value = current($permissions);

        if (is_numeric($key)) {
            return $this->getPermissionChecksRecursive($value, $context, $typeKeys, $type);
        }

        if (in_array($key, $typeKeys, true)) {
            $type = $key;
        }

        if (is_array($value)) {
            $checks = [];
            foreach ($value as $key2 => $value2) {
                $checks = array_merge($checks, $this->getPermissionChecksRecursive([$key2 => $value2], $context, $typeKeys, $type));
            }
            $resolvePermissions = $permissions;
            if ($type && $key !== $type) {
                $resolvePermissions = [$type => $permissions];
            }
            $checks[] = [
            'permissions' => $permissions,
            'resolve' => $this->lpProxy->checkAccess($resolvePermissions, $context, false),
            ];

            return $checks;
        }

        if ($key === $type) {
            return [[
            'permissions' => $permissions,
            'resolve' => $this->lpProxy->checkAccess($permissions, $context, false),
            ], ];
        }

        $checks = [];
        $resolveValue = $value;
        if ($type) {
            $resolveValue = [$type => $resolveValue];
        }
        $checks[] = [
        'permissions' => $value,
        'resolve' => $this->lpProxy->checkAccess($resolveValue, $context, false),
        ];

        $resolvePermissions = $permissions;
        if ($type) {
            $resolvePermissions = [$type => $resolvePermissions];
        }
        $checks[] = [
        'permissions' => $permissions,
        'resolve' => $this->lpProxy->checkAccess($resolvePermissions, $context, false),
        ];

        return $checks;
    }
1140517
protected function canOne(array $permissions)
    {
        foreach ($permissions as $permission) {
            if ($this->hasPermission($permission)) {
                return true;
            }
        }

        return false;
    }
454913
public function getPermissions()
    {
        $mode     = \RecursiveIteratorIterator::CHILD_FIRST;
        $iterator = $this->createRecursiveIterator($mode);

        $permissions = [];

        /** @var $child RoleInterface */
        foreach ($iterator as $child) {
            $permissions = array_replace_recursive($permissions, $child->getPermissions());
        }

        return array_replace_recursive($permissions, $this->permissions);
    }
215045
public function syncPermissions($permissions)
    {
        $mappedPermissions = [];

        foreach ($permissions as $permission) {
            $mappedPermissions[] = Helper::getIdFor($permission, 'permission');
        }

        $changes = $this->permissions()->sync($mappedPermissions);
        $this->flushCache();
        $this->fireLaratrustEvent("permission.synced", [$this, $changes]);

        return $this;
    }
1020320
public function getItemsPermissions($names)
    {
        $permissions = array();

        $items = $this->getPermissions();
        $flat = $this->flattenPermissions($items);

        foreach ($flat as $itemName => $item) {
            if (in_array($itemName, $names)) {
                $permissions[$itemName] = $item;
            }
        }

        return $permissions;
    }
11326
public function getPermissionsAttribute($permissions)
	{
		if ( ! $permissions)
		{
			return array();
		}

		if (is_array($permissions))
		{
			return $permissions;
		}

		if ( ! $_permissions = json_decode($permissions, true))
		{
			throw new \InvalidArgumentException("Cannot JSON decode permissions [$permissions].");
		}

		return $_permissions;
	}
644001
private function cumulatePermissions(array $userPermission, array $permissions)
    {
        return $this->mapPermissions($userPermission, $permissions, function($permission1, $permission2) {
            return $permission1 || $permission2;
        });
    }
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);
    }
90361
public function canAll($permissions, &$failed = null)
    {
        $this->canAny($permissions, $failed);

        return $failed->isEmpty();
    }
670836
public static function check($permissions)
    {
        if (Schema::hasTable('laralum_permissions')) {
            foreach ($permissions as $permission) {
                if (!self::allCached()->contains('slug', $permission['slug'])) {
                    Cache::forget('laralum_permissions');
                    if (!self::allCached()->contains('slug', $permission['slug'])) {
                        Permission::create([
                            'name'        => $permission['name'],
                            'slug'        => $permission['slug'],
                            'description' => $permission['desc'],
                        ]);
                    }
                }
            }
        }
        session(['laralum_permissions::mandatory' => array_merge(static::mandatory(), $permissions)]);
    }
1080245
private function restrictPermissions(array $userPermission, array $permissions)
    {
        return $this->mapPermissions($userPermission, $permissions, function($permission1, $permission2) {
            return $permission1 && $permission2;
        });
    }
603569
public function has($permissions, $all = true)
    {
        if (! is_array($permissions)) {
            $permissions    =   (array) $permissions;
        }

        $permissions=   array_unique($permissions);
        $filtered   =   array_where($permissions, [$this, 'hasFilter']);

        if (true === $all) {
            return count($permissions) === count($filtered);
        }

        return 0 < count($filtered);
    }
18772
public static function formatPermissions(array $userPermissions): array
    {
        $userPermissions = self::format($userPermissions);

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

        return $userPermissions;
    }