GitIgnore

Class
implements GitIgnoreInterface
Read only: Yes Final: Yes

Represents a .gitignore file with its path and entries.

Description

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

Tags
@implements

Description

GitIgnoreInterface

Table of Contents

Interfaces

GitIgnoreInterface

Defines the contract for a .gitignore file with its path and entries.

Properties

 : array<string|int, mixed>
 : string

Methods

__construct()

Initializes a GitIgnore instance with the given path and entries.

 : mixed
entries()

Returns the list of entries from the .gitignore file.

 : array<int, string>
fromFile()

Creates a GitIgnore instance from a file path.

 : static
getIterator()

Returns an iterator over the .gitignore entries.

 : ArrayIterator<int, string>
path()

Returns the file system path to the .gitignore file.

 : string
Properties

$entries

Public
public array<string|int, mixed> $entries
Methods

__construct()

Public

Initializes a GitIgnore instance with the given path and entries.

public __construct( string  $path, array<int, string>  $entries) : mixed
Parameters
$path : string

Description

the file system path to the .gitignore file

$entries : array<int, string>

Description

the .gitignore entries

entries()

Public

Returns the list of entries from the .gitignore file.

public entries() : array<int, string>
Return values
array<int, string>

Description

the non-empty .gitignore entries

fromFile()

Public Static

Creates a GitIgnore instance from a file path.

public static fromFile( string  $gitignorePath) : static

Description

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.

Parameters
$gitignorePath : string

Description

the file system path to the .gitignore file

Return values
static

Description

a new GitIgnore instance

getIterator()

Public

Returns an iterator over the .gitignore entries.

public getIterator() : ArrayIterator<int, string>

Description

This method implements the IteratorAggregate interface.

Return values
ArrayIterator<int, string>

Description

an iterator over the entries

path()

Public

Returns the file system path to the .gitignore file.

public path() : string
Return values
string

Description

the absolute path to the .gitignore file