@param array $unfiltered
@param       $prefix
@param int   $flag

@return array
325650
public static function filterPrefixedElements(array $unfiltered, $prefix, $flag = 0)
    {
        $useKeys      = $flag & Utils::FILTER_USE_KEYS;
        $removePrefix = $flag & Utils::FILTER_REMOVE_PREFIX;

        $startsWithPrefix = Utils::createStartWithFunction($prefix);
        if ($useKeys) {
            $filtered = [];
            foreach ($unfiltered as $key => $value) {
                if ($startsWithPrefix($key)) {
                    $filtered[ $key ] = $value;
                }
            }
        } else {
            $filtered = array_filter($unfiltered, $startsWithPrefix);
        }
        if (!$removePrefix) {
            return $filtered;
        }

        $prefixLength = strlen($prefix);

        $filteredAndStripped = [];
        if ($useKeys) {
            foreach ($filtered as $key => $value) {
                $key                         = substr($key, $prefixLength);
                $filteredAndStripped[ $key ] = $value;
            }
        } else {
            foreach ($filtered as $key => $value) {
                $value                       = substr($value, $prefixLength);
                $filteredAndStripped[ $key ] = $value;
            }
        }

        return $filteredAndStripped;
    }
1237921
public static function glob(string $pattern, int $flags = 0): array
    {
        $pattern = Path::clean($pattern);

        if (strpos($pattern, '**') === false) {
            $files = glob($pattern, $flags);
        } else {
            $position = strpos($pattern, '**');
            $rootPattern = substr($pattern, 0, $position - 1);
            $restPattern = substr($pattern, $position + 2);
            $patterns = [$rootPattern . $restPattern];
            $rootPattern .= DIRECTORY_SEPARATOR . '*';

            while ($dirs = glob($rootPattern, GLOB_ONLYDIR)) {
                $rootPattern .= DIRECTORY_SEPARATOR . '*';

                foreach ($dirs as $dir) {
                    $patterns[] = $dir . $restPattern;
                }
            }

            $files = [];

            foreach ($patterns as $pat) {
                $files[] = static::glob($pat, $flags);
            }

            $files = array_merge(...$files);
        }

        $files = array_unique($files);

        sort($files);

        return $files;
    }
43877
public function toArray($flag = self::EXTR_DATA)
    {
        $this->sort();

        if ($flag == self::EXTR_BOTH) {
            return $this->items;
        }

        return array_map(
            function ($item) use ($flag) {
                return ($flag == PriorityList::EXTR_PRIORITY) ? $item['priority'] : $item['data'];
            },
            $this->items
        );
    }
353919
public function glob($pattern = '*', $flag = 0) {
        $files = [];
        foreach (glob($this->fullName.'/'.$pattern, $flag) as $item) {
            if (is_dir($item)) {
                $files[] = new static($item);
                continue;
            }
            $files[] = new File($item);
        }
        return $files;
    }
34607
public function listPrefixedTags($prefix)
    {
        $tags = $this->listTags();
        $len  = strlen($prefix);

        if (0 >= $len) {
            return $tags;
        }

        $tags = array_filter(
            $tags,
            function ($t) use ($prefix, $len) {
                return $prefix === substr($t, 0, $len);
            }
        );

        return array_values($tags);
    }
562441
public function getFilterQuery(array $default = array(), $allowed = array())
    {
        $query = $this->query;
        foreach ($query as $key => $value) {

            if (!is_string($value)) {
                continue;
            }

            if ($key === 'sort' && strpos($value, '-') !== false) {
                list($sort, $order) = explode('-', $value, 2);
                $query['sort'] = $sort;
                $query['order'] = $order;
            }

            if ($value === 'any') {
                unset($query[$key]);
            }
        }

        $query += $default;

        if (empty($allowed)) {
            return $query;
        }

        return array_intersect_key($query, array_flip($allowed));
    }
1360281
protected function sanitizeFlags(array $flags)
    {
        $flags = (array) $flags;

        // Flip array if necessary
        $firstKey = Arr::get(array_keys($flags), 0);
        if ($firstKey !== null && is_int($firstKey)) {
            $flags = array_combine(
                array_values($flags),
                array_fill(0, count($flags), null)
            );
        }

        return $flags;
    }
841243
public function getFilters()
    {
        $roles = user_roles(true);
        unset($roles[DRUPAL_AUTHENTICATED_RID]);

        return [
            (new Filter('status', $this->t("Active")))->setChoicesMap(
                [
                    0 => $this->t("No"),
                    1 => $this->t("Yes"),
                ]
            ),
            (new Filter('role', $this->t("Role")))->setChoicesMap($roles),
            (new Filter('name', $this->t("Name"))),
        ];
    }
1074919
public static function grep(array $arr, string $pattern, int $flags = 0): array
    {
        return Strings::pcre('\preg_grep', [$pattern, $arr, $flags]);
    }
539785
public function getFilters()
    {
        if (null === $this->sorted) {
            if (!count($this->filters)) {
                $this->sorted = array();
            } else {
                ksort($this->filters);
                $this->sorted = call_user_func_array('array_merge', $this->filters);
            }
        }
        return $this->sorted;
    }
252077
public function get(string $prefix, bool $fuzzy = false, bool $withPayloads = false, int $max = -1): array
    {
        $args = [
            $this->indexName,
            $prefix,
        ];
        if ($fuzzy) {
            $args[] = 'FUZZY';
        }
        if ($withPayloads) {
            $args[] = 'WITHPAYLOADS';
        }
        if ($max >= 0) {
            $args[] = 'MAX';
            $args[] = $max;
        }
        return $this->redisClient->rawCommand('FT.SUGGET', $args);
    }
388440
public function getFilterable(bool $assoc = false): array
	{
		if ($this->filterable === self::ALLOW_ALL) {
			return self::ALLOW_ALL;
		}

		return $assoc ? $this->filterable : array_keys($this->filterable);
	}
20894
private function applyPrefix(array $array, $prefix = null)
    {
        if ($prefix === null) {
            return $array;
        }

        $result = [];
        foreach ($array as $key => $value) {
            $result[$prefix . self::PREFIX_GLUE . $key] = $value;
        }

        return $result;
    }
662554
public function filterPrefix($prefix)
    {
        $names = [];

        foreach ($this->getMethods() as $method) {
            if ($method->isPublic() && substr_count($method->getName(), $prefix, null, strlen($prefix))) {
                $names[] = $method->getName();
            }
        }

        return $names;
    }
434859
private function getImportFilters($prefix = 'filter')
    {
        $filters = [];
        try {
            $methods = (new \ReflectionClass(static::class))->getMethods();
            foreach ($methods as $methodDetails) {
                $methodName = $methodDetails->name;
                if (stripos($methodName, $prefix) === 0) {
                    $filters[] = [$this, $methodName];
                }
            }

        } catch (\ReflectionException $ex) {

        }
        return $filters;
    }
111695
private function _filterFields($aFields, $sPrefix)
    {
        $aAllowed = [];
        foreach ($aFields as $sKey => $sValue) {
            if (strpos($sValue, $sPrefix) === 0) {
                $aAllowed[] = $aFields[$sKey];
            }
        }

        return $aAllowed;
    }
925374
protected static function maskHasFlag($mask, $flag)
    {
        $flag   = (int)$flag;
        return ((int)$mask & $flag) === $flag;
    }