lithium\core\Libraries::_filter PHP Method

_filter() protected static method

Filters a list of library search results by the given set of options.
protected static _filter ( array $libs, array $config, array $options = [] ) : array
$libs array List of found libraries.
$config array The configuration of the library currently being searched within.
$options array The options used to filter/format `$libs`.
return array Returns a copy of `$libs`, filtered and transformed based on the configuration provided in `$options`.
    protected static function _filter($libs, array $config, array $options = array())
    {
        if (is_callable($options['format'])) {
            foreach ($libs as $i => $file) {
                $libs[$i] = $options['format']($file, $config);
            }
            $libs = $options['name'] ? preg_grep("/{$options['name']}\$/", $libs) : $libs;
        }
        if ($exclude = $options['exclude']) {
            if (is_string($exclude)) {
                $libs = preg_grep($exclude, $libs, PREG_GREP_INVERT);
            } elseif (is_callable($exclude)) {
                $libs = array_values(array_filter($libs, $exclude));
            }
        }
        if ($filter = $options['filter']) {
            if (is_string($filter)) {
                $libs = preg_grep($filter, $libs);
            } elseif (is_callable($filter)) {
                $libs = array_filter(array_map($filter, $libs));
            }
        }
        return $libs;
    }