Skip to content

GitIgnore

github-actions edited this page Apr 9, 2026 · 1 revision

Represents a .gitignore file with its path and entries.

This class implements IteratorAggregate to allow iteration over entries and provides a factory method to load .gitignore content from the file system.


Properties

path

public string $path

entries

public array $entries

Methods

__construct

Initializes a GitIgnore instance with the given path and entries.

public __construct(string $path, list<string> $entries): mixed

Parameters:

Parameter Type Description
$path string the file system path to the .gitignore file
$entries list the .gitignore entries

path

Returns the file system path to the .gitignore file.

public path(): string

Return Value:

the absolute path to the .gitignore file


entries

Returns the list of entries from the .gitignore file.

public entries(): list<string>

Return Value:

the non-empty .gitignore entries


getIterator

Returns an iterator over the .gitignore entries.

public getIterator(): \ArrayIterator<int,string>

This method implements the IteratorAggregate interface.

Return Value:

an iterator over the entries


fromFile

Creates a GitIgnore instance from a file path.

public static fromFile(string $gitignorePath): static

If the file does not exist, returns an empty GitIgnore with the given path. Empty lines and whitespace-only lines are filtered from the entries.

  • This method is static. Parameters:
Parameter Type Description
$gitignorePath string the file system path to the .gitignore file

Return Value:

a new GitIgnore instance


Clone this wiki locally