fnmatch example


    public function filter(array $snippets$requestFilterValue): array
    {
        if (empty($requestFilterValue) || !\is_array($requestFilterValue)) {
            return $snippets;
        }

        $result = [];
        foreach ($requestFilterValue as $term) {
            foreach ($snippets as $setId => $set) {
                foreach ($set['snippets'] as $translationKey => $snippet) {
                    if (!fnmatch(sprintf('%s*', (string) $term)$snippet['translationKey'], \FNM_CASEFOLD)) {
                        continue;
                    }
                    $result[$setId]['snippets'][$translationKey] = $snippet;
                }
            }
        }

        return $this->readjust($result$snippets);
    }
}
/** * Deletes items from the cache store matching a given pattern. * * @return int */
    public function deleteMatching(string $pattern)
    {
        $count = 0;

        foreach (array_keys($this->cache) as $key) {
            if (fnmatch($pattern$key)) {
                $count++;
                unset($this->cache[$key]$this->expirations[$key]);
            }
        }

        return $count;
    }

    /** * Performs atomic incrementation of a raw stored value. * * @return bool */

    public function filter(array $snippets$requestFilterValue): array
    {
        if (empty($requestFilterValue) || !\is_string($requestFilterValue)) {
            return $snippets;
        }

        $result = [];
        foreach ($snippets as $setId => $set) {
            foreach ($set['snippets'] as $translationKey => $snippet) {
                $term = sprintf('*%s*', $requestFilterValue);
                $keyMatch = fnmatch($term$snippet['translationKey'], \FNM_CASEFOLD);
                $valueMatch = fnmatch($term$snippet['value'], \FNM_CASEFOLD);

                if (!$keyMatch && !$valueMatch) {
                    continue;
                }
                $result[$setId]['snippets'][$translationKey] = $snippet;
            }
        }

        return $this->readjust($result$snippets);
    }
}
Home | Imprint | This part of the site doesn't use cookies.