public static function filter(array $paths, $glob, $flags = self::FILTER_VALUE)
    {
        if (($flags & self::FILTER_VALUE) && ($flags & self::FILTER_KEY)) {
            throw new InvalidArgumentException('The flags Glob::FILTER_VALUE and Glob::FILTER_KEY cannot be passed at the same time.');
        }

        if (!self::isDynamic($glob)) {
            if ($flags & self::FILTER_KEY) {
                return isset($paths[$glob]) ? array($glob => $paths[$glob]) : array();
            }

            $key = array_search($glob, $paths);

            return false !== $key ? array($key => $glob) : array();
        }

        $staticPrefix = self::getStaticPrefix($glob, $flags);
        $regExp = self::toRegEx($glob, $flags);
        $filter = function ($path) use ($staticPrefix, $regExp) {
            return 0 === strpos($path, $staticPrefix) && preg_match($regExp, $path);
        };

        if (PHP_VERSION_ID >= 50600) {
            $filterFlags = ($flags & self::FILTER_KEY) ? ARRAY_FILTER_USE_KEY : 0;

            return array_filter($paths, $filter, $filterFlags);
        }

        // No support yet for the third argument of array_filter()
        if ($flags & self::FILTER_KEY) {
            $result = array();

            foreach ($paths as $path => $value) {
                if ($filter($path)) {
                    $result[$path] = $value;
                }
            }

            return $result;
        }

        return array_filter($paths, $filter);
    }
public static function filter(array $paths, $glob, $flags = self::FILTER_VALUE)
    {
        if (($flags & self::FILTER_VALUE) && ($flags & self::FILTER_KEY)) {
            throw new InvalidArgumentException('The flags Glob::FILTER_VALUE and Glob::FILTER_KEY cannot be passed at the same time.');
        }

        if (!self::isDynamic($glob)) {
            if ($flags & self::FILTER_KEY) {
                return isset($paths[$glob]) ? array($glob => $paths[$glob]) : array();
            }

            $key = array_search($glob, $paths);

            return false !== $key ? array($key => $glob) : array();
        }

        $staticPrefix = self::getStaticPrefix($glob, $flags);
        $regExp = self::toRegEx($glob, $flags);
        $filter = function ($path) use ($staticPrefix, $regExp) {
            return 0 === strpos($path, $staticPrefix) && preg_match($regExp, $path);
        };

        if (PHP_VERSION_ID >= 50600) {
            $filterFlags = ($flags & self::FILTER_KEY) ? ARRAY_FILTER_USE_KEY : 0;

            return array_filter($paths, $filter, $filterFlags);
        }

        // No support yet for the third argument of array_filter()
        if ($flags & self::FILTER_KEY) {
            $result = array();

            foreach ($paths as $path => $value) {
                if ($filter($path)) {
                    $result[$path] = $value;
                }
            }

            return $result;
        }

        return array_filter($paths, $filter);
    }
public static function filter ( array $ paths , $ glob , $ flags = self :: FILTER_VALUE ) { if ( ( $ flags & self :: FILTER_VALUE ) && ( $ flags & self :: FILTER_KEY ) ) { throw new InvalidArgumentException ( 'The flags Glob::FILTER_VALUE and Glob::FILTER_KEY cannot be passed at the same time.' ) ; } if ( ! self :: isDynamic ( $ glob ) ) { if ( $ flags & self :: FILTER_KEY ) { return isset ( $ paths [ $ glob ] ) ? array ( $ glob => $ paths [ $ glob ] ) : array ( ) ; } $ key = array_search ( $ glob , $ paths ) ; return false !== $ key ? array ( $ key => $ glob ) : array ( ) ; } $ staticPrefix = self :: getStaticPrefix ( $ glob , $ flags ) ; $ regExp = self :: toRegEx ( $ glob , $ flags ) ; $ filter = function ( $ path ) use ( $ staticPrefix , $ regExp ) { return 0 === strpos ( $ path , $ staticPrefix ) && preg_match ( $ regExp , $ path ) ; } ; if ( PHP_VERSION_ID >= 50600 ) { $ filterFlags = ( $ flags & self :: FILTER_KEY ) ? ARRAY_FILTER_USE_KEY : 0 ; return array_filter ( $ paths , $ filter , $ filterFlags ) ; } // No support yet for the third argument of array_filter() if ( $ flags & self :: FILTER_KEY ) { $ result = array ( ) ; foreach ( $ paths as $ path => $ value ) { if ( $ filter ( $ path ) ) { $ result [ $ path ] = $ value ; } } return $ result ; } return array_filter ( $ paths , $ filter ) ; }
Filters an array for paths matching a glob.

The filtered array is returned. This array preserves the keys of the
passed array.

```php
$filteredPaths = Glob::filter($paths, '/project/**.twig');
```

@param string[] $paths A list of paths.
@param string   $glob  The canonical glob. The glob should contain
forward slashes as directory separators only. It
must not contain any "." or ".." segments. Use the
"webmozart/path-util" utility to canonicalize
globs prior to calling this method.
@param int      $flags A bitwise combination of the flag constants in
this class.

@return string[] The paths matching the glob indexed by their original
keys.
Filters an array for paths matching a glob .