public function isIgnored($name, array $ignore, array $force, $dirName)
    {
        $vName = substr($name, strlen($dirName));
        if (in_array($vName, $force, true)) {
            return false;
        }
        // first check if there is line that overrides other lines
        foreach ($ignore as $pattern) {
            if (0 !== strpos($pattern, '!')) {
                continue;
            }
            $pattern = ltrim($pattern, '!');
            // the ! negates the line, otherwise the syntax is the same
            if ($this->isIgnored($name, [$pattern], $force, $dirName)) {
                return false;
            }
        }
        foreach ($ignore as $pattern) {
            if (false !== strpos($pattern, '**')) {
                $pattern = str_replace('**', '*', $pattern);
                //$pattern = str_replace('*/*', '*', $pattern);
                if ('/' == substr($pattern, 0, 1)) {
                    $vName = '/' . $vName;
                }
                if ('.' == substr($vName, 0, 1)) {
                    $vName = '/' . $vName;
                }
                if (fnmatch($pattern, $vName, FNM_PATHNAME)) {
                    return true;
                } elseif ('*/*' === $pattern && fnmatch('*', $vName, FNM_PATHNAME)) {
                    // this a special case, where a double asterisk must match also files in the root dir
                    return true;
                }
            } elseif ('/' == substr($pattern, -1)) { // trailing slash
                if ('/' == substr($pattern, 0, 1)) {
                    $pattern = substr($pattern, 1); // remove possible starting slash
                }
                $escPattern = str_replace(['.', '*'], ['\.', '.*'], $pattern);
                if (preg_match('#^' . $escPattern . '#', $vName) > 0) {
                    return true;
                }
            } elseif (false === strpos($pattern, '/')) { // no slash
                $escPattern = str_replace(['.', '*'], ['\.', '.*'], $pattern);
                if (preg_match('#^' . $escPattern . '#', $vName) > 0) {
                    return true;
                }
            } elseif ('/' == substr($pattern, 0, 1)) {    // starting slash
                $escPattern = str_replace(['.', '*'], ['\.', '.*'], $pattern);
                if (preg_match('#^' . $escPattern . '#', '/' . $vName) > 0) {
                    return true;
                }
            } else {
                $escPattern = str_replace(['.', '*'], ['\.', '.*'], $pattern);
                if (preg_match('#^' . $escPattern . '#', $vName) > 0) {
                    return true;
                }
            }
        }

        return false;
    }
public function isIgnored($name, array $ignore, array $force, $dirName)
    {
        $vName = substr($name, strlen($dirName));
        if (in_array($vName, $force, true)) {
            return false;
        }
        // first check if there is line that overrides other lines
        foreach ($ignore as $pattern) {
            if (0 !== strpos($pattern, '!')) {
                continue;
            }
            $pattern = ltrim($pattern, '!');
            // the ! negates the line, otherwise the syntax is the same
            if ($this->isIgnored($name, [$pattern], $force, $dirName)) {
                return false;
            }
        }
        foreach ($ignore as $pattern) {
            if (false !== strpos($pattern, '**')) {
                $pattern = str_replace('**', '*', $pattern);
                //$pattern = str_replace('*/*', '*', $pattern);
                if ('/' == substr($pattern, 0, 1)) {
                    $vName = '/' . $vName;
                }
                if ('.' == substr($vName, 0, 1)) {
                    $vName = '/' . $vName;
                }
                if (fnmatch($pattern, $vName, FNM_PATHNAME)) {
                    return true;
                } elseif ('*/*' === $pattern && fnmatch('*', $vName, FNM_PATHNAME)) {
                    // this a special case, where a double asterisk must match also files in the root dir
                    return true;
                }
            } elseif ('/' == substr($pattern, -1)) { // trailing slash
                if ('/' == substr($pattern, 0, 1)) {
                    $pattern = substr($pattern, 1); // remove possible starting slash
                }
                $escPattern = str_replace(['.', '*'], ['\.', '.*'], $pattern);
                if (preg_match('#^' . $escPattern . '#', $vName) > 0) {
                    return true;
                }
            } elseif (false === strpos($pattern, '/')) { // no slash
                $escPattern = str_replace(['.', '*'], ['\.', '.*'], $pattern);
                if (preg_match('#^' . $escPattern . '#', $vName) > 0) {
                    return true;
                }
            } elseif ('/' == substr($pattern, 0, 1)) {    // starting slash
                $escPattern = str_replace(['.', '*'], ['\.', '.*'], $pattern);
                if (preg_match('#^' . $escPattern . '#', '/' . $vName) > 0) {
                    return true;
                }
            } else {
                $escPattern = str_replace(['.', '*'], ['\.', '.*'], $pattern);
                if (preg_match('#^' . $escPattern . '#', $vName) > 0) {
                    return true;
                }
            }
        }

        return false;
    }
public function isIgnored ( $ name , array $ ignore , array $ force , $ dirName ) { $ vName = substr ( $ name , strlen ( $ dirName ) ) ; if ( in_array ( $ vName , $ force , true ) ) { return false ; } // first check if there is line that overrides other lines foreach ( $ ignore as $ pattern ) { if ( 0 !== strpos ( $ pattern , '!' ) ) { continue ; } $ pattern = ltrim ( $ pattern , '!' ) ; // the ! negates the line, otherwise the syntax is the same if ( $ this -> isIgnored ( $ name , [ $ pattern ] , $ force , $ dirName ) ) { return false ; } } foreach ( $ ignore as $ pattern ) { if ( false !== strpos ( $ pattern , '**' ) ) { $ pattern = str_replace ( '**' , '*' , $ pattern ) ; //$pattern = str_replace('*/*', '*', $pattern); if ( '/' == substr ( $ pattern , 0 , 1 ) ) { $ vName = '/' . $ vName ; } if ( '.' == substr ( $ vName , 0 , 1 ) ) { $ vName = '/' . $ vName ; } if ( fnmatch ( $ pattern , $ vName , FNM_PATHNAME ) ) { return true ; } elseif ( '*/*' === $ pattern && fnmatch ( '*' , $ vName , FNM_PATHNAME ) ) { // this a special case, where a double asterisk must match also files in the root dir return true ; } } elseif ( '/' == substr ( $ pattern , - 1 ) ) { // trailing slash if ( '/' == substr ( $ pattern , 0 , 1 ) ) { $ pattern = substr ( $ pattern , 1 ) ; // remove possible starting slash } $ escPattern = str_replace ( [ '.' , '*' ] , [ '\.' , '.*' ] , $ pattern ) ; if ( preg_match ( '#^' . $ escPattern . '#' , $ vName ) > 0 ) { return true ; } } elseif ( false === strpos ( $ pattern , '/' ) ) { // no slash $ escPattern = str_replace ( [ '.' , '*' ] , [ '\.' , '.*' ] , $ pattern ) ; if ( preg_match ( '#^' . $ escPattern . '#' , $ vName ) > 0 ) { return true ; } } elseif ( '/' == substr ( $ pattern , 0 , 1 ) ) { // starting slash $ escPattern = str_replace ( [ '.' , '*' ] , [ '\.' , '.*' ] , $ pattern ) ; if ( preg_match ( '#^' . $ escPattern . '#' , '/' . $ vName ) > 0 ) { return true ; } } else { $ escPattern = str_replace ( [ '.' , '*' ] , [ '\.' , '.*' ] , $ pattern ) ; if ( preg_match ( '#^' . $ escPattern . '#' , $ vName ) > 0 ) { return true ; } } } return false ; }
Check if a file should be ignored

@param  string $name    file's name
@param  array  $ignore  list of ignores
@param  array  $force   list of files to force (do not ignore)
@param  string $dirName dir's name (to be removed from file's name)
@return bool
Check if a file should be ignored