yii\helpers\BaseFileHelper::lastExcludeMatchingFromList PHP Method

lastExcludeMatchingFromList() private static method

Based on last_exclude_matching_from_list() from dir.c of git 1.8.5.3 sources.
private static lastExcludeMatchingFromList ( string $basePath, string $path, array $excludes ) : string
$basePath string
$path string
$excludes array list of patterns to match $path against
return string null or one of $excludes item as an array with keys: 'pattern', 'flags'
    private static function lastExcludeMatchingFromList($basePath, $path, $excludes)
    {
        foreach (array_reverse($excludes) as $exclude) {
            if (is_string($exclude)) {
                $exclude = self::parseExcludePattern($exclude, false);
            }
            if (!isset($exclude['pattern']) || !isset($exclude['flags']) || !isset($exclude['firstWildcard'])) {
                throw new InvalidParamException('If exclude/include pattern is an array it must contain the pattern, flags and firstWildcard keys.');
            }
            if ($exclude['flags'] & self::PATTERN_MUSTBEDIR && !is_dir($path)) {
                continue;
            }
            if ($exclude['flags'] & self::PATTERN_NODIR) {
                if (self::matchBasename(basename($path), $exclude['pattern'], $exclude['firstWildcard'], $exclude['flags'])) {
                    return $exclude;
                }
                continue;
            }
            if (self::matchPathname($path, $basePath, $exclude['pattern'], $exclude['firstWildcard'], $exclude['flags'])) {
                return $exclude;
            }
        }
        return null;
    }