class GitExcludeFilter extends BaseExcludeFilter (View source)

An exclude filter that processes gitignore and gitattributes

It respects export-ignore git attributes

Properties

protected string $sourcePath from BaseExcludeFilter
protected array $excludePatterns from BaseExcludeFilter

Methods

__construct(string $sourcePath)

Parses .gitignore and .gitattributes files if they exist

bool
filter(string $relativePath, bool $exclude)

Checks the given path against all exclude patterns in this filter

array
parseLines(array $lines, callback $lineParser)

Processes a file containing exclude rules of different formats per line

array
generatePatterns(array $rules)

Generates a set of exclude patterns for filter() from gitignore rules

array
generatePattern(string $rule)

Generates an exclude pattern for filter() from a gitignore rule

array
parseGitIgnoreLine(string $line)

Callback line parser which process gitignore lines

array
parseGitAttributesLine(string $line)

Callback parser which finds export-ignore rules in git attribute lines

Details

__construct(string $sourcePath)

Parses .gitignore and .gitattributes files if they exist

Parameters

string $sourcePath Directory containing sources to be filtered

bool filter(string $relativePath, bool $exclude)

Checks the given path against all exclude patterns in this filter

Negated patterns overwrite exclude decisions of previous filters.

Parameters

string $relativePath The file's path relative to the sourcePath
bool $exclude Whether a previous filter wants to exclude this file

Return Value

bool Whether the file should be excluded

protected array parseLines(array $lines, callback $lineParser)

Processes a file containing exclude rules of different formats per line

Parameters

array $lines A set of lines to be parsed
callback $lineParser The parser to be used on each line

Return Value

array Exclude patterns to be used in filter()

protected array generatePatterns(array $rules)

Generates a set of exclude patterns for filter() from gitignore rules

Parameters

array $rules A list of exclude rules in gitignore syntax

Return Value

array Exclude patterns

protected array generatePattern(string $rule)

Generates an exclude pattern for filter() from a gitignore rule

Parameters

string $rule An exclude rule in gitignore syntax

Return Value

array An exclude pattern

array parseGitIgnoreLine(string $line)

Callback line parser which process gitignore lines

Parameters

string $line A line from .gitignore

Return Value

array An exclude pattern for filter()

array parseGitAttributesLine(string $line)

Callback parser which finds export-ignore rules in git attribute lines

Parameters

string $line A line from .gitattributes

Return Value

array An exclude pattern for filter()